【发布时间】:2019-12-16 21:21:32
【问题描述】:
(工作演示here)
我制作了一个非常简单的组件,它显示一条消息 3 秒,然后显示一条“完成”消息:
footer.component.ts
import { Component, OnInit } from '@angular/core'
@Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss']
})
export class FooterComponent implements OnInit {
waiting = true;
ngOnInit() {
setTimeout(() => this.waiting = false, 3000);
}
}
footer.component.html
<div class="footer">
<div *ngIf="waiting">Waiting 3s</div>
<div *ngIf="!waiting">Done !</div>
</div>
当添加到带有app-footer 的模板时,这个组件就像一个魅力。
但是,当使用材质的BottomSheet 动态实例化时,不会发生更改检测。变量waiting 的值正确,但显示的文本错误。我必须手动调用ChangeDetectorRef。
app.component.ts
constructor(private _bottomSheet: MatBottomSheet) {}
showBottomSheet() {
this._bottomSheet.open(FooterComponent);
}
查看 StackOverflow 后,我了解到更改检测与动态实例化组件的行为不同,但似乎唯一的变化是 @Input() 变量。这是预期的行为吗?这是 Material 的 BottomSheet 的错误吗?
【问题讨论】:
-
也许这个帖子会回答你的问题github.com/angular/components/issues/12931
标签: angular typescript angular-material