【问题标题】:Comment out a single directive or property in Angular html template注释掉 Angular html 模板中的单个指令或属性
【发布时间】:2019-12-20 04:57:19
【问题描述】:

在这个例子中,有没有办法用*ngIf(opened)[expanded] 注释掉行?

    <mat-expansion-panel
         *ngIf="block"
         (opened)="panelOpened.emit()"
         [expanded]=expanded
    >

在发布我的问题之前,我已阅读 How to comment HTML tag attribute in HTML source code?。有一个纯 html 属性的解决方案,但它在 Angular 中不起作用。

【问题讨论】:

  • 将属性重命名为 data-ngIfdata-openeddata-expanded,并且应该 Angula 忽略它们。
  • 我通常将它们移出html标签并对其进行注释
  • @Reactgular 感谢您的想法。它甚至可以使用括号:data-[expanded]

标签: html angular comments angular-template


【解决方案1】:

看起来添加data- 是最简单的解决方案。感谢@Reactgular 提出这个想法:

<mat-expansion-panel
         data-ngIf="block"
         data-(opened)="panelOpened.emit()"
         data-[expanded]=expanded
    >

【讨论】:

    猜你喜欢
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多