【发布时间】:2015-05-28 06:59:11
【问题描述】:
我已经定义了控制器以及$routeProvider,但不知何故,网页没有重定向到默认视图#/City。两个模板文件都存在于 partials 文件夹中。所以我认为那里没有问题。有人能告诉我为什么这段代码不起作用吗?
<html ng-app="MyApp">
<head>
<script src="angular.min.js"></script>
</head>
<body>
<h1>Using Routes</h1>
<div>
<div ng-view></div>
</div>
<script>
var app = angular.module("MyApp",['ngRoute']);
app.config(function($routeProvider){
$routeProvider
.when('/City',
{
templateUrl:'partials/filterByCity.html',
controller:'MainController'
})
.when('/Name',
{
templateUrl:'partials/filterByName.html',
controller:'MainController'
})
.otherwise({
redirectTo:'/City'
});
});
app.controller("MainController",function($scope){
$scope.customers=[
{name:"Mohd Kamran",city:"Bareilly"},
{name:"Nalin Gupta",city:"Lucknow"},
{name:"Akash Gupta",city:"Agra"}
];
});
</script>
</body>
</html>
【问题讨论】:
标签: angularjs angularjs-routing