我正在更新组件属性,但是未调用ngOnChanges。请查看链接的StackBlitz,以查看问题重现以及到目前为止我尝试过的所有事情:
编辑:正确的链接以查看代码
相关代码
ngOnInit() {
const testButton1 = document.getElementById('test-button1');
testButton1.addEventListener('click', function() {
console.log('about to set this.value');
console.log(this.value);
this.value = 'value set by button 1';
}.bind(this));
const testButton2 = document.getElementById('test-button2');
testButton2.addEventListener('click', this.testButtonCallback2(this), false);
const testButton3 = document.getElementById('test-button3');
testButton3.addEventListener('click', this.testButtonCallback3.bind(this), false);
}
ngOnChanges() {
console.log('ngOnChanges was called');
}
testButtonCallback2(outerThis) {
return function() {
console.log('about to set this.value');
console.log(outerThis.value);
outerThis.value = 'value is set by callback2';
}
}
testButtonCallback3() {
console.log('about to set this.value');
console.log(this.value);
this.value = 'value is set by callback3';
this.changeDetectorRef.detectChanges();
}
答案 0 :(得分:0)