我对angularJS很新,最近开始学习。当我正在阅读视频教程时,我正在试用这个应用程序。在某些时候,我卡住了,无法弄清楚我哪里出错了。请帮助!
<div>
<!-- Placeholder for views -->
<div data-ng-view=""></div>
</div>
<script src= "lib/angular/angular.min.js"></script>
<script src= "lib/angular/angular-route.min.js"></script>
<script>
var demoApp = angular.module('demoApp', []);
demoApp.config(function ($routeProvider) {
$routeProvider
.when('/',
{
controller: 'SimpleController',
templateUrl: 'Partials/View1.html'
})
.when('/view2',
{
controller: 'SimpleController',
templateUrl: 'Partials/View2.html'
})
.otherwise({ redirectTo: '/' });
});
demoApp.controller('SimpleController', function ($scope) {
$scope.customers= [
{name: 'John Smith', city: 'Phoenix'},
{name: 'John Doe', city: 'New York'},
{name: 'Jane Doe', city: 'San Francisco'}
];
$scope.addCustomer = function () {
$scope.customers.push(
{
name: $scope.newCustomer.name,
city: $scope.newCustomer.city
});
}
});
</script>
这是index.html文件。视图1如下:
<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是屁股:
<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 : name"></li>
</ul>
我哪里错了?我的输出空白了。
答案 0 :(得分:1)
您需要包含ngRoute模块。几个版本之前,它被放入了自己的模块中。
进行此更改并查看其是否有效:
var demoApp = angular.module('demoApp', ['ngRoute']);
您已为其添加了脚本文件,但未指明demoApp对其具有依赖性。