angular-route.min.js 问题 |错误 Chrome 控制台 [$injector:modulerr]
Issue with angular-route.min.js | Error Chrome Console [$injector:modulerr]
!!完全是初学者!!
我 运行 出错了 - chrome 控制台给我一个错误:
[$injector:modulerr]
问题是我还没有安装 angular-route.min.js 1.2 之后的所有 angular 版本你都应该这样做。当我安装 angular-route.min.js 时,我的麻烦就开始了,把它放在与 angular 和我的 HTML 文件相同的文件中,在代码中用 <script src="angular-route.min.js"></script>
引用它但什么也没发生。
我也放了angular.module('app.js',['ngRoute']);进入我的 js 文件。
我的代码中没有拼写错误,我已经检查过了。最重要的是,控制台给我一个错误,说 angular-route.min.js 没有找到。
欢迎大家的帮助,我在谷歌上搜索了很长时间,但一无所获。
(function () {
'use strict';
angular.module('MSgApp', []);
controller:('MsgController', MsgController);
angular.module('app.js', ['ngRoute']);
MsgController.$inject = ['$scope'];
function MsgController($scope) {
$scope.name = "Chris";
$scope.stateOfBeing = "hungry";
$scope.sayMessage = function () {
return "chris likes to eat cookies";
};
$scope.feedChris = function () {
$scope.stateOfBeing = "fed";
};
}
})();
<!DOCTYPE html>
<html ng-app='DIApp'>
<head>
<meta charset="utf-8">
<script src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script src="app.js"></script>
<title>custom attributes</title>
</head>
<body>
<div ng-app="app.js"></div>
<h1>expressions and interpolation</h1>
<div ng-controller='MsgController'>
{{name}} has a message for you: <br>
{{sayMessage()}}
<div>
<button ng-click="feedChris()">Feed chris</button>
<br>
<img ng-src="D:/stuff/coursera angular/chris_{{stateOfBeing}}.png">
</div>
</div>
</body>
</html>
angular 和 angular-route
未缩小后出现错误
根据 Whosebug --> Angular JS Uncaught Error: [$injector:modulerr]:
编辑:这就是最终解决问题的方法,也是 Chris B 所做的工作:
I have come across another code in the Coursera course and this one seems to be working after putting the three links from the answer by @ulmer-morozov into the head tag instead of referencing files on my pc. I guess that's it,
来自@ulmer-morozov的回答:
在开发环境中,我建议您使用未缩小的分配器。所有错误都变得更加有用!使用 angular.js
.
而不是 angular.min.js
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.js">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.js">
来自已接受的答案@Lauri Elias:
尝试添加这个:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
来自@Khanh TO的回答:
尝试添加:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js">
和:
angular.module('MyApp', ['ngRoute','ngResource']);
function TwitterCtrl($scope,$resource){
}
你应该只调用一次 angular.module
所有依赖项,因为你当前的代码,你正在创建一个新的 MyApp
模块 覆盖 前一个.
来自 angular documentation:
Beware that using angular.module('myModule', []) will create the
module myModule and overwrite any existing module named myModule. Use
angular.module('myModule') to retrieve an existing module.
!!完全是初学者!!
我 运行 出错了 - chrome 控制台给我一个错误:
[$injector:modulerr]
问题是我还没有安装 angular-route.min.js 1.2 之后的所有 angular 版本你都应该这样做。当我安装 angular-route.min.js 时,我的麻烦就开始了,把它放在与 angular 和我的 HTML 文件相同的文件中,在代码中用 <script src="angular-route.min.js"></script>
引用它但什么也没发生。
我也放了angular.module('app.js',['ngRoute']);进入我的 js 文件。
我的代码中没有拼写错误,我已经检查过了。最重要的是,控制台给我一个错误,说 angular-route.min.js 没有找到。
欢迎大家的帮助,我在谷歌上搜索了很长时间,但一无所获。
(function () {
'use strict';
angular.module('MSgApp', []);
controller:('MsgController', MsgController);
angular.module('app.js', ['ngRoute']);
MsgController.$inject = ['$scope'];
function MsgController($scope) {
$scope.name = "Chris";
$scope.stateOfBeing = "hungry";
$scope.sayMessage = function () {
return "chris likes to eat cookies";
};
$scope.feedChris = function () {
$scope.stateOfBeing = "fed";
};
}
})();
<!DOCTYPE html>
<html ng-app='DIApp'>
<head>
<meta charset="utf-8">
<script src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script src="app.js"></script>
<title>custom attributes</title>
</head>
<body>
<div ng-app="app.js"></div>
<h1>expressions and interpolation</h1>
<div ng-controller='MsgController'>
{{name}} has a message for you: <br>
{{sayMessage()}}
<div>
<button ng-click="feedChris()">Feed chris</button>
<br>
<img ng-src="D:/stuff/coursera angular/chris_{{stateOfBeing}}.png">
</div>
</div>
</body>
</html>
angular 和 angular-route
未缩小后出现错误根据 Whosebug --> Angular JS Uncaught Error: [$injector:modulerr]:
编辑:这就是最终解决问题的方法,也是 Chris B 所做的工作:
I have come across another code in the Coursera course and this one seems to be working after putting the three links from the answer by @ulmer-morozov into the head tag instead of referencing files on my pc. I guess that's it,
来自@ulmer-morozov的回答:
在开发环境中,我建议您使用未缩小的分配器。所有错误都变得更加有用!使用 angular.js
.
angular.min.js
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.js">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.js">
来自已接受的答案@Lauri Elias:
尝试添加这个:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
来自@Khanh TO的回答:
尝试添加:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js">
和:
angular.module('MyApp', ['ngRoute','ngResource']);
function TwitterCtrl($scope,$resource){
}
你应该只调用一次 angular.module
所有依赖项,因为你当前的代码,你正在创建一个新的 MyApp
模块 覆盖 前一个.
来自 angular documentation:
Beware that using angular.module('myModule', []) will create the module myModule and overwrite any existing module named myModule. Use angular.module('myModule') to retrieve an existing module.