2016-05-23 74 views
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]}}總是有效。

+0

我重新編輯,現在你可以看到我的問題 – moskitos

回答

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]應該是不帶引號的;如果像引用它那樣引用,則會將變量名稱本身作爲類名。

(或者更好的是,計算出這一切指令或控制器內,這可能是在模板中被嵌入了太多的邏輯。)