异步设置时,mat-expansion-panel [expanded] 输入无法正常工作
我有一个 mat-accordion,它有一个 mat-expansion-panel 设置如下:
<mat-expansion-panel *ngFor="let item of menuItems; index as i" [hideToggle]="item.hideToggle" [expanded]="item.active">
如果“item”的布尔属性“active”评估为 true,则可以看到“expanded”输入为 true。好吧,这是奇怪的部分:如果同步设置“item.active”,例如在我的组件的 ngOnInit 方法上,则一切正常并且面板打开。但是,如果“item.active”被异步设置,例如在可观察的“订阅”方法内,则面板不会打开。为什么会发生这种情况?我该如何解决?
先感谢您, 托马斯
I have a mat-accordion which has a mat-expansion-panel set like this:
<mat-expansion-panel *ngFor="let item of menuItems; index as i" [hideToggle]="item.hideToggle" [expanded]="item.active">
You can see the "expanded" input is true if "item" has the boolean property "active" evaluating as true. Well, here is the weird part: if "item.active" is set synchronously, for example on the ngOnInit method of my component, everything works and the panel opens. However, if "item.active" is set asynchronously, e.g. inside a "subscribe" method of an observable, panel does not open. Why does this happen, and how can I fix it?
Thank you in advance,
Thomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的问题,我异步加载扩展面板的内容。该问题是由于当内容通过返回对象作为标识的默认
trackByFunction
实现发生更改时,ngFor
指令重新渲染 DOM 引起的。请参阅此处。来解决这个问题
我通过提供自定义 trackBy 函数然后在模板中调用它
I had a similar problem as this where I was loading the contents of the expansion panel asynchronously. The issue is caused by
ngFor
directive re-rendering the DOM when the contents change via the defaulttrackByFunction
implementation that returns the object as the identity.see here.I got around this by providing my custom trackBy function
then invoking it in the template