未捕获的TypeError:$ scope.getalb.push不是函数(...)

时间:2016-02-24 09:26:50

标签: javascript jquery angularjs html5 angular-ui-bootstrap

1。我想在本地存储中插入二维数组。

  1. 我遇到错误Uncaught TypeError:$ scope.getalb.push不是条件的其他部分的函数(...)。
  2. //app.js
    var homeApp= angular.module("homeApp",['ngStorage']);
    
    
    homeApp.controller("homeController",function($scope,$localStorage){
    
      $scope.myFun=function(){
                $scope.leads = document.homeForm.leads.value;
                $scope.email = document.homeForm.email.value;
                $scope.phone = document.homeForm.phone.value;
    
                $scope.referance = document.homeForm.referance.value;
                if ($scope.referance == "ByReferance") {
                        $scope.nameref = document.homeForm.nameref.value;
                    };
                $scope.preftime = document.homeForm.preftime.value;            
                $scope.dataArra = [{"leads":$scope.leads , "email":$scope.email, 
                             "phone":$scope.phone, "referance":$scope.referance, 
                             "nameref":$scope.nameref, "preftime":$scope.preftime}];
    
                $scope.getalb =localStorage.getItem('Leads');
    
                if (!JSON.parse($scope.getalb)) {
    
                      localStorage.setItem('Leads', JSON.stringify($scope.dataArra));
    
                    } else {
                     debugger
                      $scope.getalb = $scope.getalb.push($scope.dataArra);
    
                      $localStorage.setItem('Leads', JSON.stringify($scope.getalb));
                    }
           }
    
    });
    

1 个答案:

答案 0 :(得分:2)

$ scope.getalb不是一个数组。所以你不能推入它。 如果你想要$ scope.dataArra到$ scope.getalb做

$scope.getalb=$scope.dataArra