0
UIルータのRootModule.otherwise
では、ユーザがアプリケーションが認識しないURLを開いている場合に、ユーザをリダイレクトする場所を指定できます。私は、単純な形式、対象の状態の名前を指定するだけで文字列を使用してきました:UIルータの `otherwise`関数のサービスへのアクセス
@NgModule({
imports: [UIRouterModule.forRoot({
states: [
{
name: "home",
url: "/home",
component: HomeComponent
}
],
otherwise: "/home"
})],
exports: [UIRouterModule],
providers: []
})
export class AppRoutingModule { }
をしかし、今、私はユーザーをリダイレクトすべき対象の状態を判断するために、サービスを呼び出すことで、データを取得する必要があります。私は、インジェクタのホールドを取得する方法を見つけることができない、
otherwise: (matchValue, url: UrlParts, router: UIRouter) => {
// this didn't work, router.globals.transition is not available
const userPrefSvc = router.globals.transition.injector().get(UserPreferenceService);
}
しかし、それは動作しませんでした:私は、インジェクタを通じて、私のサービスへのアクセスを得ることができることを望んでotherwise
の関数形式を試してみました。
otherwise
機能からサービスにアクセスできますか?