在HTML中加入AngularJS模块
Including AngularJS modules in HTML
我最近一直在尝试学习AngularJS,但我似乎无法让我的HTML看到我所做的angular模块。如果绑定不与模块交互,它们似乎可以工作…
我的HTML:
<!DOCTYPE html>
<html ng-app="productsModule">
<head>
<meta charset="UTF-8">
<script src="../lib/dependencies/angular.min.js"></script>
<script src="../lib/dependencies/angular-resource.min.js"></script>
<script src="../scripts/products.module.js"></script>
<title>ProductsTestPage</title>
</head>
<body>
<div ng-contoller="ProductListJSController as productList">
<h1>Product Test Page</h1>
<span>Total number of products: {{ productList.total() }}</span>
<span>{{ productList.test }}</span>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Price (£)</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in productList.products">
<td>{{product.id}}</td>
<td>{{product.name}}</td>
<td>{{product.price}}</td>
</tr>
</tbody>
</table>
<p> 1 + 2 = {{1+2}} </p>
</div>
</body>
</html>
我的JS:
angular.module('productsModule', [])
.controller('ProductListJSController', function(){
//var productList = this;
this.test = 'test';
this.products = [
{id: 53, name:'gnome 1', price: 50},
{id: 54, name:'gnome 2', price: 70},
{id: 55, name:'gnome 3', price: 90}];
this.total = function(){
var count = 0;
angular.forEach(this.products, function(){
count += 1;
});
return count;
};
});
我很确定我所做的一切都是正确的,它与我发现的示例基本相同,但它似乎没有显示任何引用product模块的绑定。
检查拼写:
<div ng-contoller="ProductListJSController as productList">
<div ng-controller="ProductListJSController as productList">
试试$scope
:-
angular.module('productsModule', [])
.controller('ProductListJSController', function($scope){
//var productList = this;
$scope.test = 'test';
$scope.products = [
{id: 53, name:'gnome 1', price: 50},
{id: 54, name:'gnome 2', price: 70},
{id: 55, name:'gnome 3', price: 90}];
$scope.total = function(){
var count = 0;
angular.forEach(this.products, function(data){
count += 1;
});
return count;
};
});
相关文章:
- 我可以像其他库一样将JointJS作为AngularJS模块注入吗
- 如何组合angularjs模块
- angularjs模块不工作
- AngularJs-模块已定义,但仍然得到“;不可用”;错误
- 检查AngularJS模块是否已启动
- 无法在coffeescript中加载angularjs模块
- 无法弄清楚为什么 angularJS 模块无法加载
- AngularJS 模块注入
- 继续得到 AngularJS 模块不可用 (ASP.NET 5)
- 列出 AngularJS 模块中声明的指令/控制器
- 如何在脚本标记的源属性中使用 AngularJS 模块常量
- AngularJS 模块与 CommonJS/ECMA6 模块
- JavaScript 和 AngularJs 模块的区别和用法
- 如何卸载 angularjs 模块
- 创建 angularjs 模块
- Angularjs 模块未正确加载
- 使用Grunt管理AngularJS模块的版本和发布
- 如何将angularJS模块加载到应用程序中
- AngularJS模块中的多重配置
- AngularJS模块应该在自己的文件中吗