所以我在我的angular应用程序中创建了这个组件,并绑定了一个对象:
Component.js
angular.module("app").component( "component", {
controller: function() {
var ctrl = this;
ctrl.createInstance = function() {
ctrl.binding = new Object();
}
},
bindings: {
binding: "="
},
templateUrl: "component.html"
});
App.html
<div ng-repeat="item in Object.items">
<component binding="item"></component>
</div>
如果我在我的组件中执行createInstance()
,它会解除对象的绑定吗?如果是这样,我如何在创建对象的新实例时保持绑定?
发布于 2017-04-18 23:54:11
经过一些摆弄之后,我发现它确实改变了对对象的引用。一种解决方法是使用angular.copy()
。
ctrl.createInstance = function() {
angular.copy(ctrl.binding, new Object());
}
https://stackoverflow.com/questions/43475790
复制相似问题