javascript – 如何在角度2组件中单击时更改布尔值

前端之家收集整理的这篇文章主要介绍了javascript – 如何在角度2组件中单击时更改布尔值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何连接按钮以更改其下方指令中[codeOnly]值的值?

我在打字稿中使用Angular 2.4.10.

  1. <button class="btn btn-primary">
  2. Click me to change all of the [codeOnly] values below to true
  3. </button>
  4.  
  5. <app-header [codeOnly]='false'></app-header>
  6.  
  7. <app-power-bi-wrapper [codeOnly]='false'></app-power-bi-wrapper>
  8.  
  9. <app-power-bi-wrapper-mobile [codeOnly]='false'></app-power-bi-wrapper-mobile>
  10.  
  11. <app-page-title [codeOnly]='false'></app-page-title>
  12.  
  13. <app-page-title-nav [codeOnly]='false'></app-page-title-nav>

解决方法

在包含HTML添加的组件中
  1. isFoo:boolean = false;

然后将HTML更改为

  1. <button class="btn btn-primary" (click)="isFoo = true" >
  2. Click me to change all of the [codeOnly] values below to true
  3. </button>
  4.  
  5. <app-header [codeOnly]='isFoo'></app-header>
  6.  
  7. <app-power-bi-wrapper [codeOnly]='isFoo'></app-power-bi-wrapper>
  8.  
  9. <app-power-bi-wrapper-mobile [codeOnly]='isFoo'></app-power-bi-wrapper-mobile>
  10.  
  11. <app-page-title [codeOnly]='isFoo'></app-page-title>
  12.  
  13. <app-page-title-nav [codeOnly]='isFoo'></app-page-title-nav>

或切换

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

猜你在找的JavaScript相关文章