我有一个BookDetailComponent
为 url 映射的组件/books/:id
。angular 2 路由器中是否有任何方法可以确保仅在从服务器检索到Book
with given后才打开该组件?id
我正在寻找类似的功能,如Angular 2 路由器中的ui-router 解析。
/*** 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());
}
}