3

I'm in a big fix since this morning for a very silly reason. This should work but I don't understand whats stopping it. Anyways, code below

My Resolver:

export class UserResolver implements Resolve<any> {
   constructor(private fakeApi: FakeApiService) { }
   resolve():Observable<any> {
     console.log('resolver method hit');
     return Observable.empty();
   }
}

My Module:

 const routes: Routes = [
    {path:'',component:UserComponent,resolve:{users:UserResolver}}
 ]

 const leafManifest:IManifestCollection = [
    {path:'',component:UserComponent}
 ]

Don't worry about the service or the calling component because they dont even come in to the picture. I am just calling this route and the resolve method is hit. However, the resolve method is not executed, it just jumps to the closing of the method and back to the calling component. In other words, if I place a debugger on resolver method, it is hit but never goes inside it. It just skips it , it seems.

So, as you can see it doesnt show any message like 'resolver method hit' in the console.

Yes, I have added UserResolver in providers of module.

BigBadWolf
  • 133
  • 1
  • 3
  • 9

1 Answers1

2

I hope you didn't Specify your Resolver under NgModule.

@NgModule({
  providers: [
    UserResolver 
  ]
})

Here a example: https://alligator.io/angular/route-resolvers/

Updated Solution:

Try this

@Injectable()
export class UserResolver implements Resolve<Observable<any>> {
  constructor(private fakeApi: FakeApiService) { }

  resolve() {
    console.log('resolver method hit');
     return Observable.empty();
  }
}
Alwin Jose
  • 696
  • 1
  • 5
  • 13
  • Yes, I have added UserResolver in providers of module. --mentioned in the main post itself – BigBadWolf Mar 14 '20 at 11:53
  • No, it doesnt. However, I'd like to point out that this UserComponent is the base component and is a container which contains other dynamic components which are loaded dynamically. – BigBadWolf Mar 14 '20 at 12:47
  • Got it. May i know any error/warning in console window while calling the Resolver? – Alwin Jose Mar 15 '20 at 06:48