【发布时间】:2017-01-13 19:52:15
【问题描述】:
我正在使用 AngularJS 1.5 创建一系列动态表单组件。
我正在使用 ng-if 来显示和隐藏表单组件。当组件被销毁时,我将它从它的父级数组中删除,但我还想将传入的双向绑定对象的值设置为 null。
以下是我正在使用的代码的简化版本:
app.component('textInput', {
bindings: {
model: '='
},
require: {
parent:'^formPanel'
},
templateUrl: 'app/shared/form/formFields/textInput/textInputView.html',
controller: function() {
var self = this;
this.$onInit = function() {
this.parent.addField(this);
},
this.$onDestroy = function() {
this.model = null;
console.log(this);
this.parent.removeField(this);
}
}
});
这会将值记录为 null,但在组件范围之外,angular 尚未注册更改,我无法运行摘要周期,因为 $onDestroy 事件已经在进行中。
【问题讨论】:
标签: javascript angularjs angularjs-components