2017-07-21 8 views
0

マイアプリのコンポーネントは、次のコンポーネントがあります。私は、バナーやフッタを必要としないページを構築していAngular 2でコンポーネントを非表示にする方法はありますか?

<login-bar></login-bar> 
    <banner></banner> 
    <navbar></navbar> 
    <router-outlet></router-outlet> 
    <footer></footer> 

。これらのコンポーネントをカスタム表示で非表示にする方法はありますか?

ありがとうございます。

+0

'* ngIf'だけ使用できますか? –

答えて

1

TypeScriptファイルにブール変数を作成し、それをfalseに設定するか、または表示するかどうかを制御するいくつかの方法を使用できます。トリックを行う必要があり、あなたのHTML部分図

<footer *ngIf="myFuncThatReturnsBoolean()"></footer> 

@Component({ 
    ... // your settings 
}) 
export class MyComponent { 

    myFuncThatReturnsBoolean(): boolean { 
     // If you need some logic to determine 
     // whether to turn it on or off, do it here 
     // otherwise 
     return false; 
    } 
} 

そして:あなたのコンポーネントを定義し、あなたのtypescriptファイルで。

+0

ショット!それはトリックをした:) – HappyCoder

関連する問題