私は私が(私のカスタムservice.tsの角度素材ダイアログ)MdDialogに送信コンポーネントサービスごとにcomponentInstanceプロパティのセットを変更するときのライフサイクルフックの必要性は何ですか?
dialogRef = this.dialog.open(component, config);
を持っていると私はそのようcomponentInstanceにより、このコンポーネントのパブリックプロパティを変更します。
dialogRef.componentInstance.task = task;
角度は私にエラーを示しています。オープンmodal.service.ts
のError: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: 'dialog'. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?
完全なコードを
@Injectable()
export class TasksPopupService {
constructor(
private dialog: MdDialog,
private router: Router,
private tasksService: TasksService
) { }
public open(component: any, id?: string) {
if (id) {
this.tasksService.find(id)
.subscribe(task => {
this.bindDialog(component, task);
});
} else {
this.bindDialog(component, new Task());
}
}
bindDialog(component, task: Task) {
let dialogRef;
let config = new MdDialogConfig();
config.height = '80%';
config.width = '70%';
dialogRef = this.dialog.open(component, config);
dialogRef.componentInstance.task = task;
dialogRef.afterClosed().subscribe(res => {
this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true });
});
return dialogRef;
}
}
しかし、idが定義されていない場合は、エラーが(ELSEブロックで)のみ発生した私はそれが理由のだと思います(非同期)、およびブロックELSEが非同期ではありません観測返しthis.tasksService.find。確信はないけど。
これはエラーをよりよく理解するのに役立ちます[「ExpressionChangedAfterItHasBeenCheckedError'エラーについて知っておくべきことすべて」(https://blog.angularindepth.com/everything-you-need-to-know-ab--ex-pressionchangedafterithbithcheckederithasbeencheckederror -error-e3fd9ce7dbb4) –
ええ、私はそれを見つけました。それをありがとう。私はミディアムであなたに続いた! –
それは素晴らしいです、あなたは大歓迎です –