mirror of https://github.com/abpframework/abp.git
8 changed files with 20 additions and 76 deletions
@ -1,47 +0,0 @@ |
|||||
import { Component, OnInit, Type } from '@angular/core'; |
|
||||
import { ActivatedRoute } from '@angular/router'; |
|
||||
import { distinctUntilChanged } from 'rxjs/operators'; |
|
||||
import { ReplaceableComponents } from '../models/replaceable-components'; |
|
||||
import { ReplaceableComponentsService } from '../services/replaceable-components.service'; |
|
||||
import { SubscriptionService } from '../services/subscription.service'; |
|
||||
import { CommonModule } from '@angular/common'; |
|
||||
|
|
||||
@Component({ |
|
||||
selector: 'abp-replaceable-route-container', |
|
||||
template: ` |
|
||||
<ng-container *ngComponentOutlet="externalComponent || defaultComponent"></ng-container> |
|
||||
`,
|
|
||||
imports: [CommonModule], |
|
||||
providers: [SubscriptionService], |
|
||||
}) |
|
||||
export class ReplaceableRouteContainerStandaloneComponent implements OnInit { |
|
||||
defaultComponent!: Type<any>; |
|
||||
|
|
||||
componentKey!: string; |
|
||||
|
|
||||
externalComponent?: Type<any>; |
|
||||
|
|
||||
constructor( |
|
||||
private route: ActivatedRoute, |
|
||||
private replaceableComponents: ReplaceableComponentsService, |
|
||||
private subscription: SubscriptionService, |
|
||||
) {} |
|
||||
|
|
||||
ngOnInit() { |
|
||||
this.defaultComponent = this.route.snapshot.data.replaceableComponent.defaultComponent; |
|
||||
this.componentKey = ( |
|
||||
this.route.snapshot.data.replaceableComponent as ReplaceableComponents.RouteData |
|
||||
).key; |
|
||||
|
|
||||
const component$ = this.replaceableComponents |
|
||||
.get$(this.componentKey) |
|
||||
.pipe(distinctUntilChanged()); |
|
||||
|
|
||||
this.subscription.addOne( |
|
||||
component$, |
|
||||
(res = {} as ReplaceableComponents.ReplaceableComponent) => { |
|
||||
this.externalComponent = res.component; |
|
||||
}, |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue