我想写一个简单的servcies代码如下: define([‘angular’], function (angular) {
return angular.module('services', [])
.service('UserService', function($http) {
return {};
});
});
然后我想在controllers里面去注入它 define([‘angular’], function(angular) {
var app = angular.module('controllers', ['services']);
app.controller('RegisterController', ['UserService','$scope', function($scope, UserService) {
$scope.password = "";
$scope.repeatpwd = "";
$scope.loginname = "";
$scope.register = function() {
console.log('dd');
};
}]);
return app;
}); 通过debug的时候,进入到这个controller并没有出现任何问题,然而,当我想通过一个注册按钮来调用UserService中的方法时,却出现了下面的错误: TypeError: v2.register is not a function at fn (eval at <anonymous> (http://cdn.bootcss.com/angular.js/1.5.0/angular.js:14086:15), <anonymous>:4:215) at expensiveCheckFn (http://cdn.bootcss.com/angular.js/1.5.0/angular.js:15076:18) at callback (http://cdn.bootcss.com/angular.js/1.5.0/angular.js:24546:17) at Scope.$eval (http://cdn.bootcss.com/angular.js/1.5.0/angular.js:16820:28) at Scope.$apply (http://cdn.bootcss.com/angular.js/1.5.0/angular.js:16920:25) at HTMLFormElement.<anonymous> (http://cdn.bootcss.com/angular.js/1.5.0/angular.js:24551:23) at HTMLFormElement.m.event.dispatch (http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js:3:8549) at HTMLFormElement.r.handle (http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js:3:5252)
希望热心的网友能帮忙看下问题出在哪里了!