0

我的问题很简单:我正在这样做:

<div class="text-center tag row class_{{infoticket.tags[0]}}">{{infoticket.tags[0]}}</div>
<div ng-repeat="item in ticketcontent track by $index">
    <div style="display: block" 
         class="container row col-md-offset-1 col-md-8" 
         ng-class="{true: 'agent', false: 'collab_infoticket.tags[0]'}
                   [item.author_id == 591119252 || 
                    item.author_id == 619780882 || 
                    item.author_id == 653783901 || 
                    item.author_id == 645192392 || 
                    item.author_id == 513340771 || 
                    item.author_id == 513345171]">
        <div ng-class="mybind"   ng-bind-html="item.html_body"></div>
        <div>{{item.created_at | date}}</div>
        <div ng-switch="item.author_id">
            <div ng-switch-when="591119252">Agent: Mystique</div>
            <div ng-switch-when="619780882">Agent: Batman </div>
            <div ng-switch-when="653783901">Agent: Superman </div>
            <div ng-switch-when="645192392">Agent:Iron Man </div>
            <div ng-switch-when="513340771">Agent:Green Hornet </div>
            <div ng-switch-when="513345171">Agent:Tornade </div>
            <div ng-Switch-Default>Collaborateur: {{myname}}</div>
        </div>
    </div>

问题是大多数时候我的 css 课程collab_infoticket.tags[0]不起作用,所以我想知道它是否来自语法问题。奇怪的是有时它会起作用!然而,这class_{{infoticket.tags[0]}}总是有效的。

4

1 回答 1

0

我不确定您在该 ng-class 中尝试做什么是有效的语法。尝试使用三元运算符:

ng-class="(item.author_id == 591119252 || 
           item.author_id == 619780882 || 
           item.author_id == 653783901 || 
           item.author_id == 645192392 || 
           item.author_id == 513340771 || 
           item.author_id == 513345171) 
? 'agent' : collab_infoticket.tags[0]}">

请注意,collab_infoticket.tags[0]如果您希望将该变量的内容设置为类名,则应不加引号;如果按照您的方式引用,您将获得变量名本身作为类名。

(或者更好的是,在指令或控制器中计算所有这些,这可能是嵌入模板中的太多逻辑。)

于 2016-05-23T16:12:38.277 回答