angular - Angular - Renderer2:如何设置没有值的属性?
问题描述
有一篇关于Set Attribute Without value的帖子,它提供了一个很好的解决方案$('body').attr('data-body','');
但是,在我当前的 ionic 项目中,我使用 Angular 的 Renderer2 API 来操作 DOM,并且我需要动态创建一个按钮并将其设置ion-button
为属性之一。
我可以使用以下代码设置具有价值的属性,但在弄清楚如何添加没有值的属性时没有任何运气。
// Make Copy Button functional
this.renderer.setAttribute(code, 'id', 'copy-target');
this.renderer.addClass(button, 'copy-button');
this.renderer.setAttribute(button, 'data-clipboard-action', 'copy');
this.renderer.setAttribute(button, 'data-clipboard-target', '#copy-target');
this.renderer.setAttribute(button, 'ion-button', null); // this doesn't work.
任何指导表示赞赏。
解决方案
推荐阅读
- matlab - MATLAB:尝试创建 .mp4 文件时权限被拒绝
- windows - 如何在 Windows 7 上首次使用 Julia?
- json - 如何在 amp-list 中插入 html 内容
- javascript - 在数组中分组相同的字符串并计算它们
- jquery - 使用 jQuery AJAX 调用的 ASP.Net 3.5 WebMethod 引发未经授权的 401 错误
- highcharts - Highcharts 逐步缩小
- python - Selenium:找不到元素
- python - python - java.lang.Exception:找不到类 oracle.jdbc.driver.OracleDriver
- mongodb - 使用查找查询将 ISO 日期(仅日期和月份)与猫鼬中的当前日期进行比较
- postgresql - 可以在 Heroku Postgres 上安装 pgAgent 吗?