我有一个BookDetailComponent
映射为url 的组件/books/:id
.在angular 2路由器中是否有任何方法可以确保只有在从服务器检索到Book
given 后才能打开此组件id
?
我正在寻找像Angular 2路由器中的ui-router resolve类似的功能.
/*** 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()); } }
Langley.. 5
是的,通过实现OnActivate
接口并返回您正在等待加载的对象的承诺:
https://angular.io/docs/js/latest/api/router/OnActivate-interface.html
是的,通过实现OnActivate
接口并返回您正在等待加载的对象的承诺:
https://angular.io/docs/js/latest/api/router/OnActivate-interface.html