我正在尝试 AngularJS,并且一直在观看 Dan Wahlin 的 youtube 视频,但无法让路由在 Chrome 或 IE 中工作。在 FireFox 中一切正常,但仅此而已。它只是给出一个空白页。有人知道可能出了什么问题吗?
这是代码:
索引.html
<!DOCTYPE html>
<html data-ng-app="demoApp">
<head>
<title></title>
<script src="angular.min.js"></script>
<script src="foo.js"></script>
</head>
<body>
<!-- Placeholder for views-->
<div data-ng-view=""></div>
</body>
</html>
foo.js
var demoApp = angular.module('demoApp',[]);
demoApp.config(function($routeProvider){
$routeProvider.when('/view1',{templateUrl: 'Partials/View1.html',controller: 'SimpleController'});
$routeProvider.when('/view2',{templateUrl: 'Partials/View2.html',controller: 'SimpleController'});
$routeProvider.otherwise({redirectTo: '/view1'});
});
var controllers = {};
controllers.SimpleController = function($scope){
$scope.customers = [
{name:'John Doe',city:'Phoenix'},
{name:'Jane Doe',city:'New York'},
{name:'Terrence Winter',city:'Los Angeles'},
{name:'Barack Obama',city:'Washington DC'}
];
$scope.addCustomer = function(){
$scope.customers.push(
{
name: $scope.newCustomer.name,
city: $scope.newCustomer.city
});
};
}
demoApp.controller(controllers);
View1.html
<div class="container">
<h3>View 1</h3>
Name:
<br>
<input type="text" data-ng-model="filter.name"/>
<br>
<ul>
<li data-ng-repeat="cust in customers | filter:filter.name | orderBy:'name'"> {{cust.name}} - {{cust.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>
</div>
View2.html
<div class="container">
<h3>View 2</h3>
<input type="text" data-ng-model="city"/>
<br>
<ul>
<li data-ng-repeat="cust in customers | filter:city | orderBy:'city'"> {{cust.name}} - {{cust.city}}</li>
</ul>
</div>