Búsqueda de sitios web

javascript - Cómo cambiar el valor booleano al hacer clic en un componente de Angular 2


¿Cómo conecto el botón para cambiar los valores de los valores [codeOnly] en las directivas que están debajo?

Estoy usando Angular 2.4.10 en 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>

Respuesta #1

En el componente que contiene tu HTML, añade

isFoo:boolean = false;

entonces cambia el HTML a

<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>

o alternar

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

Artículos relacionados