【发布时间】:2017-06-30 18:41:36
【问题描述】:
当我的模板渲染函数时,ngOnChanges 会触发一次,然后仅在 @input 更改时触发。这是预期的行为,我该如何防止它?
孩子:
export class MobileMenuComponent implements OnInit, OnChanges {
@Input('test') dezeTest: string;
//declare menu
menu;
constructor() {
//define menu
this.menu = {state: 'inactive'};
}
togglemenu() {
var that = this;
if (that.menu.state === 'inactive'){
that.menu.state = 'active';
}
else {
that.menu.state = 'inactive';
}
}
ngOnChanges(changes: SimpleChanges) {
this.togglemenu();
}
}
【问题讨论】:
标签: javascript angular typescript