如何从ui-router状态获取子组件中的已解析对象?

时间:2017-04-25 18:17:22

标签: angular angular-ui-router

这是我的代码:

export function resolveUser(userService: UserService) {
  return userService.get();
}
 let homeState = {
  parent: 'app',
  name: 'home',
  url: '/home'
  component: HomeComponent,
  resolve: [
    { token: 'currentUser', deps: [UserService], resolveFn: resolveUser },
  ]
};

@Component({
   selector: 'app-home',
   template: '<app-menu></app-menu>'
})
export class HomeComponent {
    @Input('currentUser') user: User; //user exists
}

@Component({
   selector: 'app-menu',
   template: '<div>{{user.name}}</div>'
})
export class MenuComponent {
    @Input('currentUser') user: User; //user undefined
}

定义HomeComponent中的currentUser字段,但未定义MenuComponent,尽管MenuComponent是HomeComponent的子节点。 我如何在MenuComponent中获得currentUser?

0 个答案:

没有答案