How to change boolean value when clicked in angular 2 component

How to connect a button to change the values ​​of the [codeOnly] values ​​in the directives below?

I am using Angular 2.4.10 in 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>
+6
source share
1 answer

In the component that contains your HTML code, add

isFoo:boolean = false;

then change the HTML to

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

or to switch

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

Source: https://habr.com/ru/post/1015971/


All Articles