我有这些api调用,我想在我的角度控制器中调用它们?任何例子都会有所帮助.
app.post('/user/auth',users.auth); app.get('/user/logout',helpers.isAuthenticated,users.logout);
解决方法
你只需要像这样使用
$http
service:
angular.module('app',[]) .controller('ctrlname',['$http',function($http){ //POST sample $http.post('/user/auth',users.auth).then(function(response){ //handle your response here }); //GET sample //substitute 'param1' and 'param2' for the proper name the API is expecting these parameters $http.get('/user/logout/?param1=' + helpers.isAuthenticated + '¶m2=' + users.logout).then(function(response){ //handle your response here }); }] );