gpt4 book ai didi

javascript - 如何在 Angular 2 组件中单击时更改 bool 值

转载 作者:可可西里 更新时间:2023-11-01 02:14:37 27 4
gpt4 key购买 nike

如何连接按钮以更改其下方指令中 [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-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>

最佳答案

在包含您的 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>

或切换

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

关于javascript - 如何在 Angular 2 组件中单击时更改 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42981517/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com