AngularJs 不显示从控制器填充的列表
AngularJs does not display list populated from a controller
我正在通过教程视频学习 Angular,但我无法获得以下示例工作。该示例演示如何使用使用 View1 的路由.html该 View1 应显示客户列表(简单名称、城市对象)以及添加、筛选客户的可能性。
当我尝试该示例时,不会显示客户列表 - 我只能看到项目符号和所有标签,文本等,但没有名称列表 - 城市。当我将 View1.html 中的列表替换为硬编码列表时,它会正确显示。
这里可能出了什么问题?
法典
索引.html
<!DOCTYPE html>
<html data-ng-app="demoApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular-route.js"></script>
<script src="angularTest.js"></script>
</head>
<body>
<div>
<div ng-view></div>
</div>
</body>
</html>
视图1.html
<div class="container">
<h2>View 1</h2>
Name:
<br/>
<input type="text" data-ng-model="filter.name"/>
<br/>
<ul>
<li data-ng-repeat="cust in customers | filter:filter.name | orderBy:city"></li>
</ul>
<br/>
Customer name<br/>
<input type="text" data-ng-model="newCustomer.name"/>
<br/>
Customer city<br/>
<input type="text" data-ng-model="newCustomer.city"/>
<br/>
<button data-ng-click="addCustomer()">Add customer</button>
<br/>
<a href="#/view2">View 2</a>
视图2.html
<div class="container">
<h2>View 2</h2>
Name:
<br/>
<input type="text" data-ng-model="city"/>
<br/>
<ul>
<li data-ng-repeat="cust in customers | filter:city | orderBy:city"></li>
</ul>
角度测试.js
var app = angular.module('demoApp', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider.when('/',
{
controller: 'SimpleController',
templateUrl: 'partials/View1.html'
})
.when('/view2',
{
controller: 'SimpleController',
templateUrl: 'partials/View2.html'
})
.otherwise({redirectTo: '/'});
});
app.controller('SimpleController',
function SimpleController($scope) {
$scope.customers = [
{name: 'John Doe', city: 'New York'},
{name: 'Jane Doe', city: 'San Fransisco'},
{name: 'Joe Smith', city: 'Washington'}
];
$scope.addCustomer = function() {
$scope.customers.push(
{
name: $scope.newCustomer.name,
city: $scope.newCustomer.city
}
);
};
}
);
在你的 li 元素中 你需要把
<li data-ng-repeat="cust in customers | filter:filter.name | orderBy:city">{{cust.name}} ({{cust.city}})</li>
您应该在 li 标签内打印一些内容以显示在视图上 {{ }} 为您提供了该特权:-
<li data-ng-repeat="cust in customers | filter:city | orderBy:city">{{cust.name}} ({{cust.city}})</li>
相关文章:
- 从JSON填充列表(而不是HTML)
- 根据手机上是否存在文件,在jQuery mobile中动态填充列表视图
- Jquery Selected plugin - 由 Ajax 动态填充列表
- Jquery Chosen插件-通过Ajax动态填充列表时显示加载图标
- 如何在不重新填充列表的情况下维护下拉列表的当前信息
- 无法从承诺中填充列表并在 html - aurelia.
- 从 Indexdb 填充列表视图
- 根据onKeyUp函数中的输入控制值填充列表框
- 如何从多维数组填充列表框(组合框)
- 如何使用$.get使用Rails查询填充列表
- 如何动态地用文件内容填充列表框
- 填充列表框
- 使用jQuery在填充列表上的每个项目上单击event
- 将PHP变量传递给AngularJS,并在脚本中使用它来填充列表
- 如何在servlet中获取通过jquery添加的动态填充列表的值
- 在IE7, 8和9中填充列表时脚本失败
- 根据主id从不同的表中填充列表
- 春季自动填充列表问题
- Angular js在HTTP响应后选择填充列表
- windows8-如何在windows8中用javascript填充列表