我正在尝试将 angular-jwt 注入(inject)工厂以在身份验证函数中使用,但我不断收到错误
`错误:[ng:areq] 参数“fn”不是函数,得到字符串 http://errors.angularjs.org/1.3.15/ng/areq?p0=fn&p1=not%20a%20function%2C%20got%20string
返回新的ErrorConstructor(消息);`
代码如下:
webapp.factory('Auth', ['angular-jwt'], function($http, API_URL, $window, $location, jwtHelper ) {
此外, Angular 学习曲线似乎很尖锐,我该如何理解错误以找出失败的原因?谢谢!
最佳答案
在您的应用程序模块中注入(inject)所有必需的依赖项。这就是您在声明工厂时注入(inject)新模块的内容。
代码
var webapp = angular.module('myAppName',['angular-jwt']);
webapp.factory('Auth',['$http', 'API_URL', '$window', '$location', 'jwtHelper',
function($http, API_URL, $window, $location, jwtHelper ) {
//your c0de here
}]);
关于javascript - 似乎无法将 Angular-JWT 注入(inject)工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29995832/