删除后不更新角度数组

时间:2017-12-05 13:12:46

标签: angularjs

所以在hmtl我有这个:

accounts.length:{{accounts.length}}

我也有打印所有帐户的循环。

控制器声明:

$scope.accounts; //List of accounts

在html中,每个帐户都有一个删除按钮。单击它时,我的控制器中的代码将被执行:

myService.deleteAccount(account.id).then((res) => {
    if(res && res.status === 200){
        $scope.accounts.splice(index, 1);
    }
  })

此应用已使用标签(自己的编码标签)构建。其中一个选项卡包含带有这些帐户的列表。

现在,此代码大部分时间都有效。它始终通过服务调用从后端删除帐户。 但是,当我执行以下步骤时,在GUI中我看不到删除的帐户消失:

I go inside tab for accounts
I create a new account (which pushes to the accounts array). I can see the new account in the list
I go to another tab
I come back to account tabs
I delete an account. But it doesnt disappear. And the length is the same as if it wasn't deleted. But in the controller
the "splice" occurs and I can see that the account has been removed. But not in GUI.

有任何线索吗?

0 个答案:

没有答案