html - Angular 9 改变元素的属性值
问题描述
我正在尝试更改元素的属性值,但未在元素中设置新值
Angular 的任何最佳标准实践,通过它我们可以解决以下问题
<div name="hai" (click)=test($event) #ckechName>
在 Ts 文件中
test(event){
let exmpl=event.currentTarget
exmpl.getAttribute('name') //I am able to retrieve this valu as hai
exmp.setAttribute('name','hello') //This is value is not setting as hello in the dom..It is still showing hai
}
解决方案
试试这个解决方案
@ViewChild('ckechName', {static: true}) myCkechName:ElementRef;
在您的功能中test
,您可以这样做
this.myCkechName.nativeElement.value = 'hello';
您不需要传入$event
测试功能
希望有用
推荐阅读
- xml - 将 xsd 架构文件包含到 .net 核心 Web 应用程序中
- assembly - 几何形状
- node.js - 使用 Nginx 进行服务器端渲染输出 HTML 字符串
- c - 有没有办法转储所有本机内存?
- c - 编写一个在c中分割间隔的函数
- javascript - 在为 forEach 循环中的每个单独循环设置状态后如何具有回调函数?
- python - Django - 来自图像的 SuspiciousFileOperation 添加到本地开发环境
- c# - 根据选择将目录从源复制到目标
- r - 将鼠标悬停在 R 中的 DataTable 值上?
- r - 将组合 .csv 文件中的多个轨迹绘制为不同颜色