我希望您能帮助我实现列表和详情页面。
我有一个名为motorList.html
的页面,其中列出了所有从服务器(数据库)检索到的电机,并以超链接
的形式呈现。
motorList.html
<div>
<ul class="phones">
<li ng-repeat="motor in motors" >
<a href="#/motors/{{motor.Id}}">{{motor.Name}}
</li>
</ul>
</div>
当用户点击任何电机链接时,系统应导航到
motorDetails.html
页面并显示所点击/选定的电机的详细信息。为此,在 app.js 中定义以下路由:
app.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/motors', {
templateUrl: 'View/motorlist.html',
controller: 'motorController'
}).
when('/motors/:motorId', {
templateUrl: 'View/motordetail.html',
controller: 'motorDetailsController'
}).
otherwise({
redirectTo: '/motors'
});
}]);
motorDetails.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div>
<ul class="phones">
<li ng-repeat="motor in motors" class="thumbnail">
<p>{{motor.Name}} {{motor.Make}} {{motor.Model}} {{motor.Year}} {{motor.Kilometers}} {{motor.Price}} {{motor.Color}} {{motor.SellerType}}</p>
</li>
</ul>
</div>
</body>
</html>
motorDetailsController.js
var app = angular.module('myApp', ['ngSanitize', 'ui.select']);
app.controller('motorDetailsController', function ($scope, $routeParams, motorService) {
$scope.motors = null;
$scope.getMotorDetails = function (Id) {
motorService.getByMake(Id)
.success(function (motors) {
$scope.motors = motors;
})
.error(function (error) {
$scope.status = 'Unable to load motor data: ' + error.message;
});
}
});
问题:
当我点击任何电机超链接时,它没有导航到motorDetails.html
页面,但是URL会改变,例如:http://localhost:12270/View/motorList.html#/motors/161
。
我对AngularJs路由不熟悉,肯定有些地方出了问题,但不确定哪里错了。
请问有人能指导我一下吗? 谢谢
ng-view
? - Arg0n