mirror of https://github.com/abpframework/abp.git
6 changed files with 69 additions and 9 deletions
@ -1,3 +1,4 @@ |
|||||
export * from './dynamic-layout.component'; |
export * from './dynamic-layout.component'; |
||||
export * from './replaceable-route-container.component'; |
export * from './replaceable-route-container.component'; |
||||
export * from './router-outlet.component'; |
export * from './router-outlet.component'; |
||||
|
export * from './replaceable-route-container-standalone.component'; |
||||
|
|||||
@ -0,0 +1,47 @@ |
|||||
|
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