Html push不是函数Angularjs错误

Html push不是函数Angularjs错误,html,angularjs,Html,Angularjs,我是Angularjs的初学者,现在就开始学习。 我有一个web应用程序,我想在其中向列表中添加密码。数据来自一个数据库。 在项目开始时,我将数据保存在json文件中,而不是数据库中。在我更改(数据库上的数据)之后,我得到了以下错误 我得到了以下代码: $scope.savePassword = function () { if ($scope.currentPassword.Id == null) { $scope.passwords.push($scope.curre

我是Angularjs的初学者,现在就开始学习。 我有一个web应用程序,我想在其中向列表中添加密码。数据来自一个数据库。 在项目开始时,我将数据保存在json文件中,而不是数据库中。在我更改(数据库上的数据)之后,我得到了以下错误

我得到了以下代码:

$scope.savePassword = function () {
    if ($scope.currentPassword.Id == null) {
        $scope.passwords.push($scope.currentPassword);
        $scope.isShownEdit = false;
    } else {
        var index = $scope.passwords.findIndex(function (item) {
            return item.Id == $scope.currentPassword.Id;
        });
        $scope.passwords[index] = $scope.currentPassword;
        $scope.isShownEdit = false;
    }
}
这里我得到了应该保存的数据

<div>
     <!-- Name des Passwortes -->
     <div class="cClearFloat cInputSpace">
         <input placeholder="Name" maxlength="12" ng-model="currentPassword.Name">
     </div>
     <!-- Passwort des Passwortes -->
     <div class="cClearFloat cInputSpace">
         <input placeholder="Passwort" maxlength="12" ng-model="currentPassword.Passwort">
     </div>
     <!-- Beschreibung des Passwortes -->
     <div class="cClearFloat cInputSpace">
         <input placeholder="Beschreibung" maxlength="25" ng-model="currentPassword.Beschreibung">
     </div>
     <!-- Liste mit den kategorien -->
     <div class="cClearFloat cInputSpace">
         <div class="divSmall">
             <label class="inputDropdownPlaceholder">Kategorien</label>
                 <div class="divOptions" ng-repeat="item in categories.Items">
                     <label class="labelDropDown"><input type="checkbox" class="inputDropDown" ng-model="item.isChecked" ng-checked="checkedCategory(item)" ng-init="item.isChecked = checkedCategory(item)" ng-change="changedCategory(item)">{{item.Name}}</label><br>
                 </div>
         </div>
               <div class="cClearFloat cButtons">
                   <button class="cButtonSpeichern" ng-click="showAlertPassword()">Speichern</button>
                   <button class="cButtonAbbrechen" ng-click="isShownEdit = false">Abbrechen</button>
              </div>
     </div>
</div>
我实现了数据库中的数据,如下所示:

$scope.passwords = hateoasService.call('http://localhost:20670/passwords');
当我启动应用程序,并希望添加数据与“Speichen”点击我得到的错误

[]


我不知道为什么会出现此错误,有人能帮我吗?

您使用的是
currentPassword
而不是
$scope.currentPassword

更改
currentPassword
而不是
$scope.currentPassword
,您就完成了

然后,您可能正在引用$scope.current\u密码哈希,而没有声明它

在控制器启动时初始化
$scope.current_password={}

$scope.savePassword = function () {
    if ($scope.currentPassword.Id == null) {
        $scope.passwords.push($scope.currentPassword);
        $scope.isShownEdit = false;
    } else {
        var index = $scope.passwords.findIndex(function (item) {
            return item.Id == $scope.currentPassword.Id;
        });
        $scope.passwords[index] = $scope.currentPassword;
        $scope.isShownEdit = false;
    }
}

当您在代码的其他地方引用对象的两个唯一引用
$scope.currentPassword
时,您正在将
currentPassword
推送到数组中

将其更改为此应可解决您的错误:
$scope.passwords.push($scope.currentPassword)

您必须首先对其进行初始化,然后才能将元素推入其中,如下所示:

$scope.passwords = [] // in case of array, | do {} in case of json.

$scope.savePassword = function () {
    if ($scope.currentPassword.Id == null) {
        $scope.passwords.push($scope.currentPassword);
        $scope.isShownEdit = false;
    } else {
        var index = $scope.passwords.findIndex(function (item) {
            return item.Id == $scope.currentPassword.Id;
        });
        $scope.passwords[index] = $scope.currentPassword;
        $scope.isShownEdit = false;
    }
}

我修改了它,但错误是相同的。我得到这个错误是因为我修改了一些东西,忘记了写它;)。在控制器的开始处取
$scope.currentPassword={}
我在另一个控制器(全局)中得到的
$scope.currentPassword={}
代码。在
password.js第46行中有什么
这是push调用
$scope.passwords.push($scope.currentPassword)
$scope.passwords = [] // in case of array, | do {} in case of json.

$scope.savePassword = function () {
    if ($scope.currentPassword.Id == null) {
        $scope.passwords.push($scope.currentPassword);
        $scope.isShownEdit = false;
    } else {
        var index = $scope.passwords.findIndex(function (item) {
            return item.Id == $scope.currentPassword.Id;
        });
        $scope.passwords[index] = $scope.currentPassword;
        $scope.isShownEdit = false;
    }
}