Resolver is that intermediate code, which can be executed when a link has been clicked and before a component is loaded.
How to Creating a Resolver.
Create a service.
Import “Resolve” interface from ‘@angular/router’.
Implement the Resolve interface with your class
Override resolve() method.
Resolve method should have two parameters. One is routesnapshot and other one is statesnapshot. Check this link for more.
Resolve method should return a value or observable, if you want to use it later in your loaded component class.
Path should be defined as follows
{path:templateContainer,component:TemplateContainerComp,resolve:{cres:AppResolver}
How to receive data in component?
constructor(private route: ActivatedRoute){
let x = route.data.cres;
}
Source : https://codeburst.io/understanding-resolvers-in-angular-736e9db71267
How to Creating a Resolver.
Create a service.
Import “Resolve” interface from ‘@angular/router’.
Implement the Resolve interface with your class
Override resolve() method.
Resolve method should have two parameters. One is routesnapshot and other one is statesnapshot. Check this link for more.
Resolve method should return a value or observable, if you want to use it later in your loaded component class.
Path should be defined as follows
{path:templateContainer,component:TemplateContainerComp,resolve:{cres:AppResolver}
How to receive data in component?
constructor(private route: ActivatedRoute){
let x = route.data.cres;
}
Source : https://codeburst.io/understanding-resolvers-in-angular-736e9db71267
No comments:
Post a Comment