javascript AngularJS 模块不加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16734197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AngularJS module doesn't load
提问by P Griep
My module isn't loading, and I can't figure out why. Could someone help me to find out what I am doing wrong?
我的模块没有加载,我不知道为什么。有人可以帮我找出我做错了什么吗?
The following is my HTML in a file named index.html:
以下是我在名为 index.html 的文件中的 HTML:
<html ng-app="demoApp">
<head>
<title>Using AngularJS Directives and Data Binding</title>
<script type="text/javascript" src="_Script.js"></script>
<script src="angular.min.js"></script>
</head>
<body>
<!-- Get name out of array with controller using a module-->
<h3>Get names out of an array with controller using a module:</h3>
<div class ="container" ng-controller="SimpleController">
<input type="text" ng-model="search" /> {{ search }}
<ul>
<li ng-repeat="naam in namen | filter:search" >{{ naam }}</li>
</ul>
</div>
</body>
</html>
And this is the Javascript in a file named _Script.js:
这是名为 _Script.js 的文件中的 Javascript:
var demoApp = angular.module('demoApp', []);
function SimpleController($scope) {
$scope.namen = [
'John',
'Will',
'Alex'
];
}
demoApp.controller('SimpleController', SimpleController);
I've looked for everything, so maybe it is simple. But I can't find it and got stuck with it.
我已经找遍了一切,所以也许很简单。但我找不到它并被它卡住了。
Regards,
问候,
回答by Robbert
You're currently loading your _script.js first, and angular JS second. If you reorder them your script should work:
您当前正在首先加载 _script.js,然后是 angular JS。如果您重新排序它们,您的脚本应该可以工作: