私は2つのリンクとURLを持っていますが、動的に取得するのはngOnInit
です。デフォルトでは動的リンクのrouterLinkActiveがアクティブです。角度2
ngOnInit() {
this.dataService.getOptions().subscribe((options: Options) => {
if (options.mode.toLowerCase() === "live") {
this.dashboardUrl = '/';
this.welcomeUrl = 'welcome';
} else {
this.dataService.getName().subscribe((name: string) => {
this.dashboardUrl = name;
this.welcomeUrl = name + '/welcome';
});
}
});
}
とルート:
<li><a [routerLink]="welcomeUrl" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }">Getting Started</a></li>
<li><a [routerLink]="dashboardUrl" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }">Dashboard</a></li>
は、ここに私のコンポーネントである
const routes: Routes = [
{ path: '', component: DashboardComponent },
{ path: 'welcome', loadChildren: 'app/welcome/welcome.module#WelcomeModule' },
{ path: ':name', component: DashboardComponent },
{ path: ':name/welcome', loadChildren: 'app/welcome/welcome.module#WelcomeModule' },
];
しかし、私はアプリを起動したときにこれらのリンクがアクティブになります。彼らはURLを変更するリンクをクリックした後、うまく動作し始めています。
デフォルトでは、これらのリンク(URL)は空で常に有効ですか?どうすれば修正できますか?
私は修正しましたが、現在アクティブなリンクはありませんが、dashboardUrl( "/")はアクティブになっているはずです。 –
そして私はあなたが構文について正しくないと思う。このhttps://angular.io/docs/ts/latest/guide/template-syntax.html#!#property-bindingを見てください。私があなたの言ったように使用することはありません。 –
あなたは、あなたが*アングルディレクティブ*(例: 'routerLink')でプロパティバインディング*(あなたが送ったリンク)を混乱させています。 DOMプロパティにバインドします(例: '
'は、Angularディレクティブと同じではありません。あなたのルート宣言を含めて質問を更新できますか?私は混乱が 'welcomeUrl'と' dashboardUrl'が何を表していると思いますか? –
AngularChef