1
1
/** @ng 2api @module directives */
2
2
/** */
3
- import { Directive , Output , EventEmitter , ContentChildren , QueryList } from '@angular/core' ;
3
+ import { Directive , Output , EventEmitter , ContentChildren , QueryList , Host , Self , Optional } from '@angular/core' ;
4
4
import { UISref } from './uiSref' ;
5
5
import {
6
6
PathNode ,
@@ -14,10 +14,12 @@ import {
14
14
UIRouterGlobals ,
15
15
Param ,
16
16
PathUtils ,
17
+ identity ,
18
+ uniqR ,
17
19
} from '@uirouter/core' ;
18
20
19
21
import { Subscription , Observable , BehaviorSubject , of , from , combineLatest , concat } from 'rxjs' ;
20
- import { switchMap , map } from 'rxjs/operators' ;
22
+ import { switchMap , map , tap } from 'rxjs/operators' ;
21
23
22
24
/** @internalapi */
23
25
interface TransEvt {
@@ -206,8 +208,10 @@ export class UISrefStatus {
206
208
/** @internalapi */ private _srefChangesSub : Subscription ;
207
209
/** @internalapi */ private _srefs$ : BehaviorSubject < UISref [ ] > ;
208
210
/** @internalapi */ private _globals : UIRouterGlobals ;
209
- constructor ( _globals : UIRouterGlobals ) {
211
+ /** @internalapi */ private _hostUiSref : UISref ;
212
+ constructor ( @Host ( ) @Self ( ) @Optional ( ) _hostUiSref : UISref , _globals : UIRouterGlobals ) {
210
213
this . _globals = _globals ;
214
+ this . _hostUiSref = _hostUiSref ;
211
215
this . status = Object . assign ( { } , inactiveStatus ) ;
212
216
}
213
217
@@ -226,11 +230,15 @@ export class UISrefStatus {
226
230
} )
227
231
) ;
228
232
229
- // Watch the @ContentChildren UISref[] components and get their target states
233
+ const withHostSref = ( childrenSrefs : UISref [ ] ) =>
234
+ childrenSrefs
235
+ . concat ( this . _hostUiSref )
236
+ . filter ( identity )
237
+ . reduce ( uniqR , [ ] ) ;
230
238
231
- // let srefs$: Observable< UISref[]> = of(this.srefs.toArray()).concat(this.srefs.changes);
232
- this . _srefs$ = new BehaviorSubject ( this . _srefs . toArray ( ) ) ;
233
- this . _srefChangesSub = this . _srefs . changes . subscribe ( srefs => this . _srefs$ . next ( srefs ) ) ;
239
+ // Watch the @ContentChildren UISref[] components and get their target states
240
+ this . _srefs$ = new BehaviorSubject ( withHostSref ( this . _srefs . toArray ( ) ) ) ;
241
+ this . _srefChangesSub = this . _srefs . changes . subscribe ( srefs => this . _srefs$ . next ( withHostSref ( srefs ) ) ) ;
234
242
235
243
const targetStates$ : Observable < TargetState [ ] > = this . _srefs$ . pipe (
236
244
switchMap ( ( srefs : UISref [ ] ) => combineLatest < TargetState [ ] > ( srefs . map ( sref => sref . targetState$ ) ) )
0 commit comments