输入属性评估的顺序

时间:2019-04-19 11:52:12

标签: angular input properties

Angular是否以自上而下的方式评估/初始化组件输入属性?根据我的观察,确实如此,我想确认一下。

例如:

/**
 * converts row data into FormGroup using the function provided by the parent component
 * https://stackoverflow.com/a/54169646/174390
 */
@Input() getFormGroup: (row: any) => FormGroup;

/**
 * input row data
 */
@Input() set row(row: any) {
    this._row = row;
    this.updateRowForm(this._row);
}

updateRowForm(row: any) {
    // if getFormGroup input property comes after the row input property 
    // the getFormGroup will be undefined here, 
    // otherwise it will be initialized and the following call will succeed
    this.rowFormGroup = this.getFormGroup(row);
}

0 个答案:

没有答案