Angularjs 使用字符串插值在属性内使用pug mixin参数

Angularjs 使用字符串插值在属性内使用pug mixin参数,angularjs,node.js,pug,Angularjs,Node.js,Pug,我正在使用angular和pug,并且有以下模板 mixin row(label, value) tr td strong= label td span= "{{" + value + "}}" 然后我就用这个 +row("Dates", "data.dates") +row("Venue", "data.venue") +row("Meals", "data.me

我正在使用angular和pug,并且有以下模板

mixin row(label, value)
    tr       
        td 
            strong= label
        td 
            span= "{{" + value + "}}"
然后我就用这个

    +row("Dates", "data.dates")
    +row("Venue", "data.venue")
    +row("Meals", "data.meals")
它工作正常,生成以下内容,然后按预期绑定并填充数据:

<tr>
    <td>Dates</td>
    <td>{{data.dates}}</td>
</tr>
<tr>
    <td>Venue</td>
    <td>{{data.venue}}</td>
</tr>
<tr>
    <td>Meals</td>
    <td>{{data.meals}}</td>
</tr>
目的是将其编译为

<tr ng-show="data.dates && data.dates !== ''">
    <td>Dates</td>
    <td>{{data.dates}}</td>
</tr>
<tr ng-show="data.venue && data.venue !== ''">
    <td>Venue</td>
    <td>{{data.venue}}</td>
</tr>
<tr ng-show="data.meals && data.meals !== ''">
    <td>Meals</td>
    <td>{{data.meals}}</td>
</tr>
但一切都没有奏效。在文档中也找不到任何内容

我提出了一些变通方法,将属性传递给

+row("Dates", "data.dates")(ng-show="data.dates && data.dates !== ''")
在我最后的代码中,这真的很混乱

mixin row(label, value)
        tr(ng-show!=attributes.ngShow)        
            td 
                strong= label
            td 
                span(class="preserve-newlines" ng-bind-html!=attributes.ngbindhtml)= "{{" + value + "}}" 

+row("Dates", "data.dates")
+row("Venue", "data.venue")(ngShow="data.venue && data.venue !== ''")
+row("Meals", "data.meals")(ngShow="data.meals && data.meals !== ''")
+row("Accommodation", "data.accommodation")(ngShow="data.accommodation && data.accommodation !== ''")
+row("Check-in", "data.checkin")(ngShow="data.checkin && data.checkin !== ''")
+row("Donation", "data.donation")(ngShow="data.donation && data.donation !== ''")
+row("Registration", "data.registration")(ngShow="data.registration && data.registration !== ''")
+row("Contact", "data.contact")(ngShow="data.contact && data.contact !== ''")
+row("Telephone", "data.telephone")(ngbindhtml="getTrusted(data.telephone)" ngShow="data.telephone && data.telephone !== ''")
+row("Email", "data.email")(ngbindhtml="getTrusted(data.email)" ngShow="data.email && data.email !== ''")
但在这一点上,它仅仅是一个模板,我可能只是复制和粘贴,因为我已经将每一行的所有属性分别写出来,即使如果我可以在帕格混合体的属性中使用字符串插值,它们可以大大简化

那么,如何在哈巴狗混音器中的属性中使用字符串插值呢?

我问了哈巴狗,在那边某个人的帮助下,我设法找到了答案

本质上,属性字符串作为普通JavaScript表达式进行计算,因此任何形式的字符串构建都可以。我选择了ES6风格的字符串插值,因为它看起来是最好的,结果是

mixin row(label, model, html)
    tr(ng-show=`${model} && ${model} !== ''`)        
        td 
            strong= label
        td
            if html
                span(class="preserve-newlines" ng-bind-html=`getTrusted(${model})`)= "{{" + model + "}}" 
            else
                span(class="preserve-newlines")= "{{" + model + "}}" 

+row("Dates", "data.dates")
+row("Venue", "data.venue")
+row("Meals", "data.meals")
+row("Accommodation", "data.accommodation")
+row("Check-in", "data.checkin")
+row("Donation", "data.donation")
+row("Registration", "data.registration")
+row("Contact", "data.contact")
+row("Telephone", "data.telephone", true)
+row("Email", "data.email", true)
我问了帕格斯,在那边某个人的帮助下,我终于找到了答案

本质上,属性字符串作为普通JavaScript表达式进行计算,因此任何形式的字符串构建都可以。我选择了ES6风格的字符串插值,因为它看起来是最好的,结果是

mixin row(label, model, html)
    tr(ng-show=`${model} && ${model} !== ''`)        
        td 
            strong= label
        td
            if html
                span(class="preserve-newlines" ng-bind-html=`getTrusted(${model})`)= "{{" + model + "}}" 
            else
                span(class="preserve-newlines")= "{{" + model + "}}" 

+row("Dates", "data.dates")
+row("Venue", "data.venue")
+row("Meals", "data.meals")
+row("Accommodation", "data.accommodation")
+row("Check-in", "data.checkin")
+row("Donation", "data.donation")
+row("Registration", "data.registration")
+row("Contact", "data.contact")
+row("Telephone", "data.telephone", true)
+row("Email", "data.email", true)
mixin row(label, model, html)
    tr(ng-show=`${model} && ${model} !== ''`)        
        td 
            strong= label
        td
            if html
                span(class="preserve-newlines" ng-bind-html=`getTrusted(${model})`)= "{{" + model + "}}" 
            else
                span(class="preserve-newlines")= "{{" + model + "}}" 

+row("Dates", "data.dates")
+row("Venue", "data.venue")
+row("Meals", "data.meals")
+row("Accommodation", "data.accommodation")
+row("Check-in", "data.checkin")
+row("Donation", "data.donation")
+row("Registration", "data.registration")
+row("Contact", "data.contact")
+row("Telephone", "data.telephone", true)
+row("Email", "data.email", true)