/**
* New node file
*/
var app = angular.module('myApp', []);
angular.module('myApp', []).controller('orderCtrl', function($scope) {
$scope.name = '';
$scope.price = '';
$scope.total=0;
$scope.output=0;
count=0;
$scope.items = [
{id:1, Name:'Garlic Bread',price:20 },
{id:2, Name:'Butter Chicken',price:30 },
{id:3, Name:'Tandoori Chicken',price:25 },
{id:4, Name:'Naan',price:5},
{id:5, Name:'Ice Cream',price:10},
{id:6, Name:'Pizza',price:15 }
];
$scope.cal=function(id){
$scope.output = $scope.output+$scope.items[id-1].price;
$scope.fina.push({id:$scope.items[id-1], Name:$scope.items[id-1].Name,price:$scope.items[id-1].price});
}
$scope.res=function(fina){
$scope.total= $scope.output;
$scope.finals=angular.copy($scope.fina);
}
});
push函数抛出错误无法读取属性' push'未定义的角度。我想继续将项目数组的内容添加到fina数组中。还有其他方法吗?
答案 0 :(得分:1)
定义$scope.fina = new Array()
;或者$scope.fina = []
在开头。
.push函数用于数组数据。在你的情况下,$ scope.fina不是
被认为是阵列。