The exception is triggered when a value used for data binding changes as the view is being updated, which is the case for the QueryList
populated with ViewChildren
in NavigationComponent
.(当用于作为视图正在被更新,这是为的情况下的数据绑定的变化的值的异常被触发QueryList
与填充ViewChildren
在NavigationComponent
。)
You can avoid the exception this way:(您可以通过以下方式避免异常:)
Redefine the sideNavsDrawers
input property as an array:(将sideNavsDrawers
输入属性重新定义为数组:)
export class ToolbarComponent implements OnInit {
@Input() sideNavsDrawers: Array<MatSidenav>;
}
Construct the array with the template reference variables instead of using ViewChildren
:(使用模板引用变量而不是使用ViewChildren
构造数组:)
<mat-sidenav #leftDrawer ... >
...
<mat-sidenav #rightDrawer ... >
...
<app-toolbar [sideNavsDrawers]="[leftDrawer, rightDrawer]">
See this stackblitz for a demo.(有关演示,请参见此堆叠闪电战 。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…