mirror of https://github.com/abpframework/abp.git
1 changed files with 31 additions and 6 deletions
@ -1,18 +1,43 @@ |
|||||
import { Type, Component, OnInit } from '@angular/core'; |
import { Component, OnDestroy, OnInit, Type } from '@angular/core'; |
||||
import { Router, ActivatedRoute } from '@angular/router'; |
import { ActivatedRoute } from '@angular/router'; |
||||
|
import { Store } from '@ngxs/store'; |
||||
|
import { distinctUntilChanged } from 'rxjs/operators'; |
||||
|
import { ABP } from '../models/common'; |
||||
|
import { ReplaceableComponents } from '../models/replaceable-components'; |
||||
|
import { ReplaceableComponentsState } from '../states/replaceable-components.state'; |
||||
|
import { takeUntilDestroy } from '../utils/rxjs-utils'; |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-replaceable-route-container', |
selector: 'abp-replaceable-route-container', |
||||
template: ` |
template: ` |
||||
<ng-container *ngComponentOutlet="defaultComponent"></ng-container> |
<ng-container *ngComponentOutlet="externalComponent || defaultComponent"></ng-container> |
||||
`,
|
`,
|
||||
}) |
}) |
||||
export class ReplaceableRouteContainerComponent implements OnInit { |
export class ReplaceableRouteContainerComponent implements OnInit, OnDestroy { |
||||
defaultComponent: Type<any>; |
defaultComponent: Type<any>; |
||||
|
|
||||
constructor(private route: ActivatedRoute) {} |
componentKey: string; |
||||
|
|
||||
|
externalComponent: Type<any>; |
||||
|
|
||||
|
constructor(private route: ActivatedRoute, private store: Store) {} |
||||
|
|
||||
ngOnInit() { |
ngOnInit() { |
||||
this.defaultComponent = this.route.snapshot.data.component.default; |
if (!this.defaultComponent) { |
||||
|
this.defaultComponent = this.route.snapshot.data.component.default; |
||||
|
} |
||||
|
|
||||
|
if (!this.componentKey) { |
||||
|
this.componentKey = (this.route.snapshot.data.component as ABP.ComponentData).key; |
||||
|
} |
||||
|
|
||||
|
this.store |
||||
|
.select(ReplaceableComponentsState.getComponent(this.componentKey)) |
||||
|
.pipe(takeUntilDestroy(this), distinctUntilChanged()) |
||||
|
.subscribe(({ component } = {} as ReplaceableComponents.ReplaceableComponent) => { |
||||
|
this.externalComponent = component; |
||||
|
}); |
||||
} |
} |
||||
|
|
||||
|
ngOnDestroy() {} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue