0

Now I'm studying Angular 5, in the project I use restangular. my current task is to get the server response before starting the page. Can anyone help me? thanks in advance (I have responce and I can read data in compnent, but I need wait respnce in resolver)

> service

getRequest(){
...
  return this.restangular.one(url).get()
}

> resolver

readRequest(){
...
  this.service.getRequest().subscribe(data => {
    return data;
})
}

2 Answers 2

1

All you need is resolver , that can be done from the routes

{ 
    path: 'detail/:id', 
    component: HeroDetailComponent,
    resolve: {
      hero: HeroDetailResolve
    },
},

For more details read And This Also

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer, but resolver is already in routes. > resolver readRequest(){ ... this.service.getRequest().subscribe(data => { return data; }) } //router { path: 'detail/:id', component: SomeCompnent, resolve: { item: resolver(class name) }, }
0

In a resolver you have to return the observable so the Router can subscribe on it and wait for data to be returned.

1/ you forgot to return the observable 2/ you added a useless subscription on it

so try this :

> resolver

readRequest(){
...
  return this.service.getRequest();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.