web-dev-qa-db-fra.com

Comment changer la valeur booléenne au clic dans le composant angular 2

Comment connecter le bouton pour changer les valeurs des valeurs [codeOnly] dans les directives en dessous?

J'utilise Angular 2.4.10 dans TypeScript.

<button class="btn btn-primary">
     Click me to change all of the [codeOnly] values below to true
</button>

<app-header [codeOnly]='false'></app-header>

<app-power-bi-wrapper [codeOnly]='false'></app-power-bi-wrapper>

<app-power-bi-wrapper-mobile [codeOnly]='false'></app-power-bi-wrapper-mobile>

<app-page-title [codeOnly]='false'></app-page-title>

<app-page-title-nav [codeOnly]='false'></app-page-title-nav>
11
es06x

Dans le composant qui contient votre ajout HTML

isFoo:boolean = false;

puis changez le HTML en

<button class="btn btn-primary" (click)="isFoo = true" >
     Click me to change all of the [codeOnly] values below to true
</button>

<app-header [codeOnly]='isFoo'></app-header>

<app-power-bi-wrapper [codeOnly]='isFoo'></app-power-bi-wrapper>

<app-power-bi-wrapper-mobile [codeOnly]='isFoo'></app-power-bi-wrapper-mobile>

<app-page-title [codeOnly]='isFoo'></app-page-title>

<app-page-title-nav [codeOnly]='isFoo'></app-page-title-nav>

ou pour basculer

<button class="btn btn-primary" (click)="isFoo = !isFoo" >
     Click me to change all of the [codeOnly] values below to true
</button>
31
Günter Zöchbauer