这是我的代码:
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?