0

我有角度控制器,它注入一个数组:

class a{
    constructor(items){
        this.items = items;
        this.items[0].name = "abc";
    }

    edit(){
        this.items[0].name = "abc";
    })
}

如果我要更改此数组中一项的值,在构造函数内部,它将更改原始数组中该项的值。

如果我更改编辑方法中的值,它现在不会更改为原始值。

我能做些什么?

谢谢。

4

1 回答 1

0

如果您使用角度,那么您应该使用angular.copyorangular.extend分配itemsin_this.items而无需参考

var _this = this
_this.items =angular.copy(items);
于 2016-02-04T10:53:44.733 回答