Skip to content

Commit ebd2e40

Browse files
fix(ivy): Inject host UISref separately to account for behavior change in @ContentChildren
ContentChildren no longer returns the host element. UISrefStatus needs all children UISref _AND_ the host UISref (if it exists). see: angular/angular#8277 (comment)
1 parent e0981cf commit ebd2e40

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/directives/uiSrefStatus.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @ng2api @module directives */
22
/** */
3-
import { Directive, Output, EventEmitter, ContentChildren, QueryList } from '@angular/core';
3+
import { Directive, Output, EventEmitter, ContentChildren, QueryList, Host, Self, Optional } from '@angular/core';
44
import { UISref } from './uiSref';
55
import {
66
PathNode,
@@ -14,10 +14,12 @@ import {
1414
UIRouterGlobals,
1515
Param,
1616
PathUtils,
17+
identity,
18+
uniqR,
1719
} from '@uirouter/core';
1820

1921
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';
2123

2224
/** @internalapi */
2325
interface TransEvt {
@@ -206,8 +208,10 @@ export class UISrefStatus {
206208
/** @internalapi */ private _srefChangesSub: Subscription;
207209
/** @internalapi */ private _srefs$: BehaviorSubject<UISref[]>;
208210
/** @internalapi */ private _globals: UIRouterGlobals;
209-
constructor(_globals: UIRouterGlobals) {
211+
/** @internalapi */ private _hostUiSref: UISref;
212+
constructor(@Host() @Self() @Optional() _hostUiSref: UISref, _globals: UIRouterGlobals) {
210213
this._globals = _globals;
214+
this._hostUiSref = _hostUiSref;
211215
this.status = Object.assign({}, inactiveStatus);
212216
}
213217

@@ -226,11 +230,15 @@ export class UISrefStatus {
226230
})
227231
);
228232

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, []);
230238

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)));
234242

235243
const targetStates$: Observable<TargetState[]> = this._srefs$.pipe(
236244
switchMap((srefs: UISref[]) => combineLatest<TargetState[]>(srefs.map(sref => sref.targetState$)))

0 commit comments

Comments
 (0)