angularjs模块不工作
angularjs module not working
我正在学习AngularJS。我正试图列出控制器中的变量。我在剧本里有这个。
var demoController = angular.module('sampleController',[]);
demoController.controller('sampleController', function ($scope){
$scope.customers=[
{name:'John Smith', country:'Denmark', worth:'5000000'},
{name:'John Lewis',country:'England',worth:'10000000'},
{name:'Rick Evans',country:'America',worth:'6000000'}
];
});
我在HTML中有这个。
<html ng-app="demoController">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<body>
<h1>Applying filters</h1>
<div ng-controller="sampleController">
<ul>
<li ng-repeat="cust in customers">{{ cust.name }} - {{ cust.country }} - {{ cust.worth | currency:"$":2 }}</li>
</ul>
</div>
</body>
</html>
它没有列出变量。这个脚本出了什么问题。谢谢
您需要以正确的方式定义您的模块
var app = angular.module('app',[]);
然后,在HTML文件中使用它
<html ng-app="app">
看看它在jsbin 上的工作
请注意,角度模块的名称是在引号中定义的名称
angular.module('app',[]);
所以,如果你写
var xModule = angular.module('app2',[]);
,你的模块名称是app2
,而不是xModule
这是我正在使用的代码:
<meta name="robots" content="noindex">
<html data-ng-app="app">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<body>
<h1>Applying filters</h1>
<div data-ng-controller="sampleController">
<ul><li data-ng-repeat="cust in customers">{{ cust.name }} - {{ cust.country }} - {{ cust.worth | currency:"$":2 }}</li></ul>
</div>
<script id="jsbin-javascript">var app = angular.module('app',[]);
app.controller('sampleController', function ($scope){
$scope.customers=[
{name:'John Smith', country:'Denmark', worth:'5000000'},
{name:'John Lewis',country:'England',worth:'10000000'},
{name:'Rick Evans',country:'America',worth:'6000000'}
];
});
</script>
</body></html>
输出为:
Applying filters
{{ cust.name }} - {{ cust.country }} - {{ cust.worth | currency:"$":2 }}
让我知道这里缺了什么。
相关文章:
- grunt serve:dist时找不到Angular.js模块,但grunt serve工作正常
- angularjs模块不工作
- 有没有人能够得到这个要求或调试NPM模块在浏览器中工作
- 为什么模块化幂函数在 Python 和 Javascript 中对于大数字的工作方式不同
- 使用 Babel 将 ES6 模块转换为 ES5 AMD 模块,无法按预期工作
- Firefox SDK页面模块不工作
- NodeJS Semaphore模块:它是如何工作的
- 语义UI粘性模块不工作
- 节点's模块async没有'没有按预期工作
- 我很奇怪“异步”模块不能很好地工作
- 角度模块不工作
- 与控制器对话的指令 - 为什么我的模块不工作?(角度JS)
- 有没有像 Nodejs 中的 django 管理员一样工作的模块
- 哪些jQuery UI模块是动画正常工作所必需的
- 两个异步模块函数异步工作
- 可以't让这个关键字在节点模块中工作
- AngularJS应用程序组件(模块、工厂、控制器)定义的确切工作方式
- 继承和依赖项注入如何与角度模块一起工作
- 即使手动ssh可以工作,也无法使用带有ssh2模块的nodejs进行身份验证
- Meteor 0.9模数部署;t工作-“;找不到模块'纤维'&”;