我试图使用ViewChild获取子组件属性,用于Stepper [completed] 属性,但我无法解决“ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。之前的值:'completed:null'。当前值:'completed:false'”。
我按照这个答案进行操作:Angular Material Stepper Component For Each Step
parent component .ts
@ViewChild(FirstStepComponent, {static: false}) firstStepComp: FirstStepComponent;
get firstStepCompleted() {
return this.firstStepComp ? this.firstStepComp.completed : null;
}
parent component .html
<mat-step [completed]="firstStepCompleted">
<app-first-step>
</app-first-step>
</mat-step>
in the child component .ts
completed: boolean = false;
[completed]="firstStepComp?.completed"
感到疲倦了? - Ashot Aleqsanyan