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);
        } 
  });

the push function throws an error cannot read property 'push' of undefined angular. I want to keep adding the contents of item array to fina array . Is there some other way?

sachin hunur
  • 281
  • 2
  • 6
  • 17

1 Answers1

1

define $scope.fina = new Array(); or $scope.fina = [] in the begining. The .push function is for array data . In your case the $scope.fina isn't recognized as array.

J_P
  • 642
  • 1
  • 8
  • 23