有景点列表,当用户选择这些项目时,将转到所选列表,
app.controller('ItineraryNewController', function($scope) {
$scope.city = "";
$scope.attractions =[];
$scope.places = [] ;
$scope.day = 1;
$scope.getAttractions=function(){
$scope.attractions.push({
name: "LA",
description: "test la",
address: "3423 some stree",
website: "test.com"
},,
{
name: "SFO",
description: "test SFO",
address: "3423 some stree",
website: "testsfo.com"
});
}
$scope.addPlace = function(place,index){
console.log(index);
$scope.places.push($scope.attractions[index]);
}
这些地方没有更新,我认为索引值是未定义的。
该示例发布在plunker Plunker
中答案 0 :(得分:1)
您没有从模板中向函数addPlace
传递正确数量的参数。
从您的功能定义addPlace(place, index)
<button ng-click="addPlace($index)">Add</button>
<button ng-click="addPlace(place, $index)">Add</button>