这是昨天工作但现在不行!!!!请建议。 ng-app包含在我的HTML中。文件
我已经包含了所有配置文件,并且不确定为什么会发生这种情况???
这是我的app.js
'use strict';
// Declare app level module which depends on filters, and services
angular.module('myApp', [
'ngRoute',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'});
$routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
$routeProvider.otherwise({redirectTo: '/view1'});
}]);
controller.js
'use strict';
/* Controllers */
angular.module('myApp.controllers', []).
controller('MyCtrl1', function($scope, Users) {
$scope.allusers = Users.query();
})
.controller('MyCtrl2', [function() {
}]);
services.js
'use strict';
var userServices = angular.module('myApp.services', ['ngResource']);
var commentServices = angular.module('myApp.services', ['ngResource']);
userServices.factory('Users', function($resource) {
return $resource('http://localhost:8080/PingleBackend/webresources/users', {}, {
query: {method: 'GET', isArray: true},
// create: {method: 'POST'}
});
});
[$injector:unpr] Unknown provider: UsersProvider <- Users
http://errors.angularjs.org/1.2.13/$injector/unpr?p0=UsersProvider%20%3C-%20Users
http://localhost:8383/PingleFrontend/lib/angular/angular.js:3556 (23:27:33:392 | error)
at (anonymous function) (app/lib/angular/angular.js:9503:0)
at (anonymous function) (app/lib/angular/angular.js:6914:0)
at nodeLinkFn (app/lib/angular/angular.js:6274:0)
at compositeLinkFn (app/lib/angular/angular.js:5682:0)
at publicLinkFn (app/lib/angular/angular.js:5587:0)
at boundTranscludeFn (app/lib/angular/angular.js:5701:0)
at controllersBoundTransclude (app/lib/angular/angular.js:6292:0)
at update (app/lib/angular/angular-route.js:873:0)
at (anonymous function) (app/lib/angular/angular.js:12329:0)
at (anonymous function) (app/lib/angular/angular-route.js:556:0)
at (anonymous function) (app/lib/angular/angular.js:11033:0)
at (anonymous function) (app/lib/angular/angular.js:11033:0)
at (anonymous function) (app/lib/angular/angular.js:11119:0)
at (anonymous function) (app/lib/angular/angular.js:12045:0)
at (anonymous function) (app/lib/angular/angular.js:11871:0)
at (anonymous function) (app/lib/angular/angular.js:12151:0)
at done (app/lib/angular/angular.js:7909:0)
at completeRequest (app/lib/angular/angular.js:8110:0)
at (anonymous function) (app/lib/angular/angular.js:8056:0)
答案 0 :(得分:1)
尝试
angular.module('myApp.controllers', ['myApp.services'])
<强>更新强>
你有两个同名的模块
var userServices = angular.module('myApp.services', ['ngResource']);
var commentServices = angular.module('myApp.services', ['ngResource']);
不要使用全局变量!
:)