Javascript 如何在角度 2 组件中单击时更改布尔值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42981517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:34:06 来源:igfitidea点击:
How to change boolean value on click in angular 2 component
提问by es06x
How do I connect the button to change the values of the [codeOnly] values in the directives below it?
如何连接按钮以更改其下方指令中 [codeOnly] 值的值?
I'm using Angular 2.4.10 in 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-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>
回答by Günter Z?chbauer
In the component that contains your HTML add
在包含您的 HTML 的组件中添加
isFoo:boolean = false;
then change the HTML to
然后将 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>
or to toggle
或切换
<button class="btn btn-primary" (click)="isFoo = !isFoo" >
Click me to change all of the [codeOnly] values below to true
</button>

