Error: $injector:modulerr Module Error using separate .js files
Error: $injector:modulerr Module Error using separate .js files
看着所有其他答案,因为我正在努力。
我的'app.js':
angular.module('app', [
'imageCtrlController',
'adminCreateController',
'ui.bootstrap',
'ngRoute'
]);
我的另一个带有配置和两个控制器的 .js 文件:
angular.module("app").config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$routeProvider
.when('/', {
template: 'One moment please.'
})
.when('/imageCtrl', {
templateUrl: '/admin/imagecontrol',
controller: 'imageCtrlController'
})
}]);
angular.module("app").controller('adminCreateController', function AdminCreateController($scope, $http) {
$scope.admin = {};
console.log("hello");
$scope.createNewAdmin = function () {
var admin = $.param($scope.admin);
var config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post('/admin/CreateAdmin', admin, config)
.then(
function (response) {
console.log(response);
});
}
});
angular.module("app").controller('imageCtrlController', function ImageCtrlController($scope, $http) {
alert("yo");
});
在我的 _Layout 中:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
<script src="~/js/ui-bootstrap-tpls-2.5.0.min.js"></script>
<script src="~/js/AngularControllers/app.js"></script>
<script src="~/js/AngularControllers/adminController.js"></script>
我在我的 _Layout 主体中初始化 ng-app,然后为我的视图的 div 初始化。 'ng-controller="imageCtrlController"'
管理控制器工作正常,直到我将它移到一个单独的文件中。
我得到的错误是:
Error: $injector:modulerr Module Error
堆栈跟踪:
Failed to instantiate module app due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.6.4/$injector/modulerr?p0=i...)
at http://localhost:2808/js/angular.min.js:6:425
at http://localhost:2808/js/angular.min.js:42:407
at q (http://localhost:2808/js/angular.min.js:7:495)
at g (http://localhost:2808/js/angular.min.js:41:476)
at http://localhost:2808/js/angular.min.js:42:149
at q (http://localhost:2808/js/angular.min.js:7:495)
at g (http://localhost:2808/js/angular.min.js:41:476)
at eb (http://localhost:2808/js/angular.min.js:46:44)
at c (http://localhost:2808/js/angular.min.js:21:373)
at Sc (http://localhost:2808/js/angular.min.js:22:179
This error occurs when a module fails to load due to some exception. The error message above should provide additional context.
A common reason why the module fails to load is that you've forgotten
to include the file with the defined module or that the file couldn't
be loaded.
angular.module
的第二个参数用于包含其他angular模块。您正在尝试这样包含您的控制器:
angular.module('app', [
'imageCtrlController', // not a module
'adminCreateController', // ...also not a module
'ui.bootstrap', // is a module
'ngRoute' // ...is as well
]);
更正:
angular.module('app', [
'ui.bootstrap',
'ngRoute'
]);
看着所有其他答案,因为我正在努力。
我的'app.js':
angular.module('app', [
'imageCtrlController',
'adminCreateController',
'ui.bootstrap',
'ngRoute'
]);
我的另一个带有配置和两个控制器的 .js 文件:
angular.module("app").config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$routeProvider
.when('/', {
template: 'One moment please.'
})
.when('/imageCtrl', {
templateUrl: '/admin/imagecontrol',
controller: 'imageCtrlController'
})
}]);
angular.module("app").controller('adminCreateController', function AdminCreateController($scope, $http) {
$scope.admin = {};
console.log("hello");
$scope.createNewAdmin = function () {
var admin = $.param($scope.admin);
var config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post('/admin/CreateAdmin', admin, config)
.then(
function (response) {
console.log(response);
});
}
});
angular.module("app").controller('imageCtrlController', function ImageCtrlController($scope, $http) {
alert("yo");
});
在我的 _Layout 中:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
<script src="~/js/ui-bootstrap-tpls-2.5.0.min.js"></script>
<script src="~/js/AngularControllers/app.js"></script>
<script src="~/js/AngularControllers/adminController.js"></script>
我在我的 _Layout 主体中初始化 ng-app,然后为我的视图的 div 初始化。 'ng-controller="imageCtrlController"'
管理控制器工作正常,直到我将它移到一个单独的文件中。
我得到的错误是:
Error: $injector:modulerr Module Error
堆栈跟踪:
Failed to instantiate module app due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.6.4/$injector/modulerr?p0=i...)
at http://localhost:2808/js/angular.min.js:6:425
at http://localhost:2808/js/angular.min.js:42:407
at q (http://localhost:2808/js/angular.min.js:7:495)
at g (http://localhost:2808/js/angular.min.js:41:476)
at http://localhost:2808/js/angular.min.js:42:149
at q (http://localhost:2808/js/angular.min.js:7:495)
at g (http://localhost:2808/js/angular.min.js:41:476)
at eb (http://localhost:2808/js/angular.min.js:46:44)
at c (http://localhost:2808/js/angular.min.js:21:373)
at Sc (http://localhost:2808/js/angular.min.js:22:179
This error occurs when a module fails to load due to some exception. The error message above should provide additional context.
A common reason why the module fails to load is that you've forgotten to include the file with the defined module or that the file couldn't be loaded.
angular.module
的第二个参数用于包含其他angular模块。您正在尝试这样包含您的控制器:
angular.module('app', [
'imageCtrlController', // not a module
'adminCreateController', // ...also not a module
'ui.bootstrap', // is a module
'ngRoute' // ...is as well
]);
更正:
angular.module('app', [
'ui.bootstrap',
'ngRoute'
]);