Demo
StackBlitz. Spinner, Busy- app.component.ts .
:
Angular .
constructor(private templateRef: TemplateRef<void>,
private vcr: ViewContainerRef,
private cfr: ComponentFactoryResolver) { }
. (, , ), , .
, bindingPropertyName Input.
@Input('xuiBusy') isBusy: boolean;
, , createEmbeddedView, ViewContainerRef. , , : TemplateRef, .
this.vcr.createEmbeddedView(this.templateRef)
, factory, , .
resolveComponentFactory ComponentFactoryResolver.
const cmpFactory = this.cfr.resolveComponentFactory(SpinnerComponent)
factory createComponent , .
this.vcr.createComponent(cmpFactory)
, , isBusy true, .
if (this.isBusy) {
const cmpFactory = this.cfr.resolveComponentFactory(SpinnerComponent)
this.vcr.createComponent(cmpFactory)
}
Angular , . , Angular , . Spinner, .
Angular , NgModule.entryComponents.
@NgModule({
...
entryComponents: [SpinnerComponent],
...
})
@Directive({selector: '[xuiBusy]'})
export class BusyDirective implements OnInit {
@Input('xuiBusy') isBusy: boolean;
constructor(private templateRef: TemplateRef<void>,
private vcr: ViewContainerRef,
private cfr: ComponentFactoryResolver) { }
ngOnInit() {
this.vcr.createEmbeddedView(this.templateRef)
if (this.isBusy) {
const cmpFactory = this.cfr.resolveComponentFactory(SpinnerComponent)
this.vcr.createComponent(cmpFactory)
}
}
}
( )
<div *xuiBusy="true">
<span>This is some content</span>
</div>
<div *xuiBusy="false">
<span>This is some content</span>
</div>