【发布时间】:2016-04-16 12:28:00
【问题描述】:
我有一个 BookDetailComponent 组件,它映射到一个 url /books/:id。 angular 2 路由器中是否有任何方法可以确保仅在从服务器检索到具有给定id 的Book 后才打开此组件?
我正在 Angular 2 路由器中寻找类似 @987654321@ 的功能。
/*** BookComponent ***/
@RouteConfig([
{path: "/books/:id", component: BookDetailComponent, as: "BookDetail"},
])
export class BookComponent {
}
/*** BookDetailComponent ***/
export class BookDetailComponent {
book:Book;
constructor(private bookService:BookService,
private routeParams:RouteParams) {
}
ngOnInit() {
let id = this.routeParams.get("id");
this.bookService.getBook(parseInt(id))
.subscribe(book => this.book = book.json());
}
}
【问题讨论】:
标签: angular angular-ui-router angular2-routing