Javascript 如何在角度2组件中单击时更改布尔值
如何连接按钮以更改其下方指令中[codeOnly]值的值? 我在typescript中使用Angular 2.4.10Javascript 如何在角度2组件中单击时更改布尔值,javascript,angular,typescript,Javascript,Angular,Typescript,如何连接按钮以更改其下方指令中[codeOnly]值的值? 我在typescript中使用Angular 2.4.10 <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-p
<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>
单击我将下面的所有[codeOnly]值更改为true
在包含HTML添加的组件中
isFoo:boolean = false;
然后将HTML更改为
<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>
单击我将下面的所有[codeOnly]值更改为true
或者切换
<button class="btn btn-primary" (click)="isFoo = !isFoo" >
Click me to change all of the [codeOnly] values below to true
</button>
单击我将下面的所有[codeOnly]值更改为true
您必须使用同一个变量来传递给这两个变量。不太清楚您的意思<代码>isFoo=!isFoo只需在每次单击事件时在true和false之间切换isFoo即可。