How to refresh a route's resolved data

前端 未结 4 1292
执笔经年
执笔经年 2021-01-04 01:09

Consider the following route configuration:

const routes: Routes = [
  {
    path: \'\',
    component: AppComponent,
    resolve: {
      app: AppResolver
          


        
相关标签:
4条回答
  • 2021-01-04 01:34

    You can try something like this:

    constructor(private activatedRoute: ActivatedRoute) {
      this.activatedRoute.parent.data.subscribe(data => {
        this.profile = data.profile;
      });
    }
    
    updateProfile(newProfile) {
      (this.activatedRoute.parent.data as BehaviorSubject<any>).next({profile: newProfile});
    }
    
    0 讨论(0)
  • 2021-01-04 01:39

    I've tested the solution 'runGuardsAndResolvers', it works for my use case, the resolver is called at each sub-page changes.

    It is only adding this option the part of your routes that you want behave this way.

    export const ROUTES: any = [
      {
        path: 'project/:name',
        runGuardsAndResolvers: "always",
        component: ProjectComponent,
        resolve: { project: ProjectResolver },
        children: [
          ...
    
    0 讨论(0)
  • 2021-01-04 01:49

    There is a parameter you can use in your route configuration called 'runGuardsAndResolvers' that will affect when the resolver runs. In this case you would want to set it to 'always'. This means that the resolver will run any time the child routes of that route change. See the route documentation for more information.

    0 讨论(0)
  • 2021-01-04 01:57

    By above way i can call the resolver. But it not change data which comes from my backend server so i got one solution i call my service method again in success part and got new changed data from backend server.

    0 讨论(0)
提交回复
热议问题