未捕获的类型错误:$scope.getalb.push 不是一个函数(...)

Uncaught TypeError: $scope.getalb.push is not a function(…)

本文关键字:函数 一个 push getalb 类型 错误 scope      更新时间:2023-09-26

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


  1. 我遇到一个错误 未捕获的类型错误:$scope.getalb.push 不是条件的其他部分的函数(...)。
//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));
                }
       }
});

$scope.getalb 不是你不能推入的 array.so。如果你想$scope.dataArra$scope.getalb做

$scope.getalb=$scope.dataArra