angular - Angular 7(点击)不适用于 [hidden] 属性
问题描述
Angular 7(click)
事件不适用于[hidden]
属性,这是什么原因?这是我的示例代码
<div class="autocomplete-dropdown" [hidden]="!showdeviceDropDown">
<button *ngFor="let item of devices; let i= index" (click)="Save()" class="btn btn-danger">{{ item.serialNumber }}</button>
</div>
解决方案
它工作正常,您的代码中的其他地方可能存在运行时错误。在浏览器中调试或在浏览器控制台中查看错误以查看其无法正常工作的原因。
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
numOfClicks = 0;
showdeviceDropDown = true;
devices = [{serialNumber: '123'}];
Save(){
this.numOfClicks++;
}
}
app.component.html
<div> Showing = {{showdeviceDropDown}}</div>
<div [hidden]="!showdeviceDropDown">
<button *ngFor="let item of devices; let i= index" (click)="Save()">{{ item.serialNumber }}</button>
</div>
<div> Number of clicks:{{numOfClicks}}</div>
推荐阅读
- javascript - 不和谐机器人——节点 index.js 问题——“客户端未定义”
- java - 连接到 MongoDB URI 时出错,即使我可以使用 compassdb 或机器人 t3 工具
- python - 处理 Python 分页 API 请求中的最后一页
- python - 如何修改存储在列表中的一列numpy数组
- karate - 识别 JSON 属性的唯一性
- ios - AVAudioEngine - 更改 inputNode 的音频单元设备后输出格式有 0 个通道
- matlab - 如何检查系统是否有 `Simulink Coder 的许可证?
- javascript - 如何在 React 中管理组件状态(加载、错误、数据)
- vips - 带有白色背景的 libvips 中的范围图像
- omnet++ - 一个关于omnet++无线节点源码的问题