因此,我尝试使用MEAN堆栈学习Angular,而且我遇到了一个问题,即我正在玩弄一个简单的应用程序。
我现在得到的具体错误是angular.js:38 Uncaught Error: [$injector:modulerr]
,经过数小时的研究,排查和敲打我的头脑后,我似乎无法让我的应用再次运作。它有一个非常基本的app.js工作,但我改变它使用匿名函数并调整我的controller.js和factory.js。
这是我的app.js,factory.js和controller.js的代码
如果有人愿意协助我找到问题所在,我非常感谢!
app.js
(function(){
var iquueApp = angular.module('iquueApp', ['ngRoute', 'ngResource', 'iquueApp.iquueCtrl', 'iquueApp.iquueFactory'])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: '/partials/property-dashboard.html',
controller: 'iquueCtrl'
}).when('/admin', {
templateUrl: '/partials/admin-dashboard.html',
controller: 'iquueCtrl'
}).when('/admin/property-setup', {
templateUrl: '/partials/admin-prop-setup.html',
controller: 'iquueCtrl'
}).when('/login', {
templateUrl: '/auth/login/login.html',
controller: 'iquueCtrl'
})
.when('/register', {
templateUrl: '/auth/register/register.view.html',
}).otherwise({
redirectTo: '/'
});
// use the HTML5 History API
$locationProvider.html5Mode(true);
});
})();
factory.js
angular.module('iquueApp.iquueFactory',[])
.factory('iquueFactory', function($http) {
var urlBase = '/api/hubs';
var _iquueService = {};
_iquueService.getHub = function() {
return $http.get(urlBase);
};
_iquueService.saveHub = function(secretKey) {
return $http.post(urlBase, secretKey);
};
_iquueService.updateHub = function(secretKey) {
return $http.put(urlBase, secretKey);
};
_iquueService.deleteHub = function(id) {
return $http.delete(urlBase + '/' + id);
};
return _iquueService;
});
controller.js
/Angular Controllers
angular.module('iquueApp.iquueCtrl',[])
.controller('iquueCtrl', function($rootScope, $scope, iquueFactory) {
$scope.hubs = [];
$scope.isEditable = [];
// get all hubs on Load
iquueFactory.getHub().then(function(data) {
$scope.hubs = data.data;
});
});
答案 0 :(得分:0)
感谢评论家伙。此错误是由于未正确加载angular-resource.js。我在发布这个问题后不久就解决了这个问题。
答案 1 :(得分:-2)
确切的错误是什么?尝试发布控制台中显示的确切错误。这将告诉您导致错误的模块或控制器..
像这样......在这里MyApp是错误的地方......Failed to instantiate module MyApp due to:
Error: [$injector:unpr] http://errors.angularjs.org/1.3.11/$injector/unpr?p0=e
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:6:417
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:38:307
at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:36:308)
at Object.e [as invoke] (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:37:64)
at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:301)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:425
at s (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:7:302)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:202)
at Ob (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:38:435