所以我在我的角度应用程序中创建此组件,并绑定一个对象:
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()
,它将取消绑定对象吗?如果是这样,在创建对象的新实例时如何保持绑定?
最佳答案
经过一番摆弄之后,我发现它确实更改了对该对象的引用。解决方法是使用angular.copy()
。
ctrl.createInstance = function() {
angular.copy(ctrl.binding, new Object());
}