N
N
nuclear_kote2017-04-25 18:07:01
Angular
nuclear_kote, 2017-04-25 18:07:01

How to resolve the state object in a child component?

In general, there is such a state for ui-router'a

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; //Здесь все нормально
}

@Component({
   selector: 'app-menu',
   template: '<div>{{user.name}}</div>'
})
export class MenuComponent {
    @Input('currentUser') user: User; //Здесь уже пусто
}

The problem is that currentUser in HomeComponent is resolved by @Input('currentUser') user: User,
but not in child components.
Question: how to throw it into all child components?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
ozknemoy, 2017-04-29
@nuclear_kote

there is no forwarding to the lowest element from the middle

@Component({
   selector: 'app-home',
   template: '<app-menu [currentUser]="user"></app-menu>'
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question