Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolve function not getting executed in Resolver Angular 5

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.

like image 799
BigBadWolf Avatar asked Oct 13 '25 03:10

BigBadWolf


1 Answers

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();
  }
}
like image 163
Alwin Jose Avatar answered Oct 15 '25 11:10

Alwin Jose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!