【问题标题】:Can I use double quotes in an attribute value of angular directive?我可以在 angular 指令的属性值中使用双引号吗?
【发布时间】:2016-02-07 03:11:51
【问题描述】:

您能否建议如何将{{$count}} times per month <span ng-include="'views/partials/month-dates.html'"></span> 分配给translate-plural 属性?

例如以下表达式导致解析错误:

<translate translate-n="notification.Data[flightType][direction].Days.length" translate-plural="{{$count}} times per month <span ng-include=\"'views/partials/month-dates.html'\"></span>">
    N times per month on <span ng-include="'views/partials/month-dates.html'"></span>
</translate>

【问题讨论】:

  • 试试translate-plural="{{$count}} times per month &lt;span ng-include=\"views/partials/month-dates.html\""
  • 我已经解决了用 ng-include 指令中的变量替换常量的问题:
    上每月 N 次
  • 但是问题仍然存在:是否可以在角度指令中使用双引号?
  • @Tamil Selvan 您的解决方案不仅会导致解析错误,而且还有语法错误:您没有在开头使用引号转义常量。
  • 试试translate-plural="{{$count}} times per month &lt;span ng-include=\"'views/partials/month-dates.html'\""

标签: angularjs angularjs-directive quotes double-quotes


【解决方案1】:

您是否尝试过使用&amp;quot;&amp;#34;?我只是在属性内的角度表达式遇到了类似的问题,它的工作原理是这样的。

【讨论】:

    【解决方案2】:

    由于我没有收到任何好的答案,我将分享我在这个主题上的发现。

    • 似乎没有办法在Angular中转义双引号 观看次数。
    • 如果你确实需要在指令属性中使用双引号 有两种方法:

      1. 如果可能(在我的情况下不是)使用单引号来换行 属性值和属性值中的双引号,反之亦然 反之
      2. 您还可以在 像我一样带有变量的属性值

    查看下面的解决方案

    <div ng-init="monthDatesView = 'views/partials/month-dates.html'"></div>
    <translate translate-n="notification.Data[flightType][direction].Days.length" translate-plural="{{$count}} times per month on <span ng-include='monthDatesView'></span>">
        N times per month on <span ng-include="monthDatesView"></span>
    </translate>
    

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签