私のアプリでは、タブではなくメニューでボタンを使うことにしました。それぞれのボタンが別のコンポーネントにつながるときに、このナビゲーションを行う正しい方法は何かを理解したいと思います。通常のボタン(タブではなく)を使用してさまざまなコンポーネントにナビゲートする適切な方法は何ですか?
だから私は今、試したものです、MainComponent.html:
<button md-button (click)="menuButtonClicked('component-one')">Button1</button>
<button md-button (click)="menuButtonClicked('component-two')">Button2</button>
<h1>My App</h1>
<div *ngIf="shouldDisplayComponent1">
<component-one [someList]="list"></component-one>
</div>
<div *ngIf="shouldDisplayComponent2">
<component-two [someList]="list"></component-two>
</div>
MainComponent.ts:
public shouldDisplayComponent1: boolean;
public shouldDisplayComponent2: boolean;
public menuButtonClicked(componentName: string) {
switch (componentName) {
case 'component-one':
this.shouldDisplayComponent1 = true;
this.shouldDisplayComponent2 = false;
case 'component-two':
this.shouldDisplayComponent2 = true;
this.shouldDisplayComponent1 = false;
default:
throw('No such component')
}
}
ん意味をなさない?ない場合は、:) おかげ
私はそれを見たが、私は渡すことができますどのように理解していませんでしそのコンポーネントをrouterLinkでリストするには、毎回このコンポーネントをコレクションに渡す必要があります(コレクションが時々変更されるので、コレクションが新しくなります) – JohnBigs
@JohnBigsあなたはhtml内の配列のrouterLinkデータを与えることができます。ターゲットコンポーネント内のrouter.paramsからその情報を取得します。更新された回答を確認してください。 – echonax