I am trying to figure out how does Angular consumes a getById service. I start from the very beginning, I have exposed a Rest Api service that returns a Boolean value and checks if an item is in my favorite List or not : it gets the id of an element as a parameter. In my Front end, I am using a baseApi service for the Basic Crud operations and a resolver for every request: So what I need to do is how to pass the id from my method to the resolver and how to define the link structure (URL).
Here is my code for a better understanding:
- My actual getById in my baseService:
getById(link, id:number){
this.header=this.createHeader();
return this.http.get(this.apiurl+link+id,this.header).map(this.extractData);
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Item> {
return this.service.getById(item/isFavorite/1');
}
- And the method in the typescript file that gets the item that I need to send its id to the resolver:
checkItem(item : Item){
this.checkfav=this.route.snapshot.data.isfav;
/**
* checkfav is a bool that should m rest api defined in resolver return
*/
}