在Angular2我們可以使用Resolve
如下:應用下決心根組件在Angular2
import { UserResolver } from './resolvers/user.resolver.ts';
export const routes: RouterConfig = [
{
path: 'users/:id',
component: UserComponent,
resolve: {
transaction: UserResolver
}
}
];
但我如何能夠最好地應用解析器上運行,例如,我的app.component.ts
?也許當網站第一次加載時,無論什麼頁面首次加載,我總是需要首先獲取用戶數據(例如)。那麼我怎樣才能讓這個解析器在路由層次上更低?
也許你想要的東西像http://stackoverflow.com/questions/37611549/how-to-pass-parameters-rendered-from-backend-to-angular2-bootstrap-method正如AngularFrance所說,解析器只能是用於路由器添加的組件,路由組件不是。 –
也許你可以使用APP_INITIALIZER https:// hackernoon。com/hook-into-angular-initialization-process-add41a6b7e – Michael