Angular 将mat进度条与mat选项卡和惰性加载选项卡内容一起使用
在我将其从子组件移动到父组件后,我的Angular 将mat进度条与mat选项卡和惰性加载选项卡内容一起使用,angular,angular-material,Angular,Angular Material,在我将其从子组件移动到父组件后,我的“mat进度条”不再显示。我还必须修改父组件中的更改检测策略,因为避免了“检查后表达式更改”错误。进度条“不使用选项卡”和“使用选项卡直接在子组件中”起作用 child.component.ts(缩短) 导出类ChildComponent实现OnInit、OnChanges{ @输出()加载:EventEmitter=新的EventEmitter(); 构造函数(私有只读项服务:项服务){} 异步ngOnInit(){ this.loading.emit(tr
“mat进度条”
不再显示。我还必须修改父组件中的更改检测策略,因为避免了“检查后表达式更改”错误。进度条“不使用选项卡”和“使用选项卡直接在子组件中”起作用
child.component.ts(缩短)
导出类ChildComponent实现OnInit、OnChanges{
@输出()加载:EventEmitter=新的EventEmitter();
构造函数(私有只读项服务:项服务){}
异步ngOnInit(){
this.loading.emit(true);
this.itemsSubscription=this.itemsService
.getItemsByStatus(此.selectedItemsStatus)
.pipe(finalize(()=>this.loading.emit(false)))
.订阅((数据)=>{
this.dataSource.data=数据;
});
}
ngOnChanges(){
this.loading.emit(true);
this.itemsSubscription=this.itemsService
.getItemsByStatus(此.selectedItemsStatus)
.pipe(finalize(()=>this.loading.emit(false)))
.订阅((数据)=>{
this.dataSource.data=数据;
});
}
}
parent.component.ts
@组件({
changeDetection:ChangeDetectionStrategy.OnPush,
})
导出类ParentComponent实现OnInit,AfterContentChecked{
statusId:编号;
statusElements:StatusDto[];
加载:布尔值=false;
建造师(
专用只读状态服务:状态服务,
私有只读changeDetectorRef:changeDetectorRef
) {}
异步ngOnInit():承诺{
this.statusElements=等待此.statusService.getAllStatus().toPromise();
}
ngAfterContentChecked():void{
this.changeDetectorRef.detectChanges();
}
加载(事件:布尔值){
this.loading=事件;
}
}
parent.component.html
谢谢你的帮助
解决方案:从子组件中删除以下零件
ngOnChanges() {
this.loading.emit(true);
this.itemsSubscription = this.itemsService
.getItemsByStatus(this.selectedItemsStatus)
.pipe(finalize(() => this.loading.emit(false)))
.subscribe((data) => {
this.dataSource.data = data;
});
}
解决方案是删除子组件中的ngOnChanges(){…}部分。在那之后一切都很好。。。在所有东西发射两次之前。。。