2015-09-25 25 views
0
/** 
    * 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'的未定義的角度。我想繼續添加項目數組的內容到fina數組。有沒有其他的方法?angularjs:想將物品陣列推入到fina數組

+0

向我們展示了小提琴上的代碼。 – amoeba

+0

重複的http://stackoverflow.com/questions/351409/appending-to-array – frhd

回答

1

定義$scope.fina = new Array();或開頭$scope.fina = []。 .push函數用於數組數據。在你的情況下,$ scope.fina並不是 ,它被識別爲數組。

+0

非常感謝它的工作! –