我有Menu.html页面,显示菜单列表。通过单击每个菜的图像,我想引导用户到dishdetail.html页面。但是在dishdetail.html中,角度参数是未知的。
Menu.html:
<div class="tab-content">
<ul class="media-list tab-pane fade in active">
<li class="media" ng-repeat="dish in dishes| filter:filtText">
<div class="media-left media-middle">
<a href="#/menu/{{dish._id}}">
<img class="media-object img-thumbnail" ng-src={{dish.image}} alt="Uthapizza">
</a>
</div>
<div class="media-body">
<h2 class="media-heading">{{dish.name}}
<span class="label label-danger label-xs">{{dish.label}}</span>
<span class="badge">{{dish.price|currency}}</span>
</h2>
<p ng-show="showDetails">{{dish.description}}</p>
</div>
</li>
</ul>
</div>
dishdetail.html:
<div class="row row-content" ng-controller="DishDetailController">
<div class="col-xs-12">
<div class="media-left media-middle">
<a href="#/menu/{{dish._id}}">
<img class="media-object img-thumbnail" ng-src={{dish.image}} alt="Uthapizza">
</a>
</div>
<div class="media-body">
<h2 class="media-heading">{{dish.name}}
<span class="label label-danger label-xs">{{dish.label}}</span>
<span class="badge">{{dish.price|currency}}</span>
</h2>
<p>{{dish.description}}</p>
</div>
</div>
</div>
和app.js:
'use strict'
angular.module('confusionApp', ['ngRoute'])
.config(['$routeProvider',function($routeProvider) {
$routeProvider
.when('/menu', { // route for the menu pag
templateUrl : 'menu.html', controller : 'MenuController'
})
.when('/menu/:id', { // route for the dish details pag
templateUrl : 'dishdetail.html', controller : 'dishDetailController'
})
.otherwise('/menu');
}]);
controllers.js:
angular.module('confusionApp')
.controller('DishDetailController', ['$scope', '$routeParams',
'menuFactory', function($scope, $routeParams, menuFactory) {
var dish= menuFactory.getDish(parseInt($routeParams.id,10));
$scope.dish = dish;
}]);
和services.js:
'use strict'
angular.module('confusionApp')
.factory('menuFactory',function(){
var menufac = {};
var dishes=[
{
_id:0,
name:'Uthapizza',
image:'images/uthapizza.png',
category:'main',
label:'Hot',
price:'4.99',
description:'A unique combination of Indian Uthappam (pancake) and Italian pizza topped with cerignola olives, ripe vine charry tomatoes, vidalia onion, Guntour chillies.'
},
{
_id:1,
name:'Elaicheesecake',
image:'images/elaicheesecake.png',
category:'appetizer',
label:'New',
price:'4.99',
description:'A unique combination of Indian Uthappam (pancake) and Italian pizza topped with cerignola olives, ripe vine charry tomatoes, vidalia onion, Guntour chillies.'
}];
menufac.getDishes = function(){
return dishes;
};
menufac.getDish = function(index){
return dishes[index];
};
return menufac;
});
答案 0 :(得分:0)
这是因为在你的对象属性中,&#34; _id&#34;是私有属性 - 属性/变量之前的下划线表示它是私有的,只有控制器/脚本才能看到它。
一种方法是改变你的对象属性&#34; _id&#34;到&#34; id&#34;。