Angular 2 Router Using BehaviorSubject Observable in Resolve

I thought about this one overnight, and realized that I was using the resolve incorrectly. The crux of the problem is that the router expects the resolve result to eventually be completed. The BehaviorSubject, even though it only has one value at a time, will never be done, because the value can always change. I changed this._data.asObservable() to this._data.asObservable().first(), and it started working. It seems so obvious now!


For Angular 6+ to complete observable in resolver you need to do as follows:

this.myService.getData().pipe(take(1))

// or

this.myService.getData().pipe(first())