我有以下服务从我的REST API得到一个访问令牌:
I have the following service for getting an access token from my REST API:
var myServices = angular.module('myServices ', ['ngResource']);
myServices .factory('Auth', ['$resource',
function($resource){
return $resource('http://192.168.0.17:3333/login', {}, {
login: {method:'POST', params: { username: 'user1', password: 'abc123' }, isArray:false}
});
}
]);
和我有以下的控制器进行定义:
And I have the following controller defined:
var myControllers = angular.module('myControllers ', []);
myControllers.controller('AuthCtrl', ['$scope', 'Auth', function($scope, Auth) {
$scope.login = function() {
console.log('Login');
Auth.login();
};
}]);
我的登录表单如下:
My login form is as follows:
<form ng-controller="AuthCtrl">
<input type="text" name="username" id="username" placeholder="Username" ng-model="username" />
<input type="password" name="password" id="password" placeholder="Password" ng-model="userpassword" />
<button type="submit" ng-click="login();">Login</button>
</form>
在我点击登录按钮,它不叫AuthCtrl的login()函数,我想不通为什么:■
When I click the "Login" button it doesn't call the login() function of the AuthCtrl and I can't figure out why :s
我觉得你会心烦与自己。我能够通过myControllers声明之后删除空间来解决这个问题。检查:
I think that you are going to be upset with yourself. I was able to fix this by removing the space after the myControllers declarations. Check this:
var myControllers = angular.module('myControllers**YOU HAD A SPACE HERE**', []);
我将其更改为以下,和它的工作。它看起来像你将有同样的问题与您的服务。
I change it to the following, and it worked. It looks like you are going to have the same issue with your service.
var myControllers = angular.module('myControllers', []); //no space after the myControllers
看到我的code这里