子組件或指令中的 @Input() 裝飾器表示該屬性可以從其父組件中獲取值。
要想監視 @Input() 屬性的變化,你可以使用 Angular 的生命周期鈎子OnChanges.
但上述方法,對於接收到的值都是,收到就使用。
如果想對接收到參數進行一些處理 ,或者是根據參數執行不同操作。
這個時候可以使用set和get方法。
@Input()
set classMethod(type) {
if (type) {
this._classMethod = type;
this.treeList.selectedRowKeys = [];
this.initData();
}
}
get classMethod() {
return this._classMethod;
}
private _classMethod = 'clc';