簡體   English   中英

如果項目選擇器變量為true,則AngularJS添加CSS類

[英]AngularJS add css class if item selector variable is true

我有一個項目選擇器指令,我想為所選項目添加一個測試:如果已歸檔,則必須添加一個CSS類。

.directive-items-selector{ ng_click: "openItemsSelector( $event )" }
  .wrapper
    %ui_select.ui-select{ ng: { model:  "input.model", disabled: "disabled",
                                change: "itemSelectModelChanged()" },
                        search_enabled: "{{ options.searchable }}" }

      %ui_select_match.ui-select-match{ items_selector_match: '',
                                        placeholder: "{{ input.placeholder }} ",
                                        allow_clear: "{{ options.clearable }}",
                                        title:       "{{ $select.selected.label }}" }
        %i.fa{ ng_class: 'icon' }

        {{ $select.selected.label }}
        {{$select.selected.object.is_archived}}

      %ui_select_choices.ui-select-choices{ repeat:  "item.id as item in input.filteredItems track by item.id",
                                            refresh: "reloadItems( $select.search )",
                                            refresh_delay: '{{ input.filterDelay }}' }
        .item{ ng_attr_title: "{{ ::item.label }}" }
          .item-label {{ ::item.label }}
          %small.item-details {{ ::item.details }}

    .items-selector-actions
      %a.pointer.action{ ng: { if: 'linkToModal', click: 'openDetails()', disabled: "!model"  }}
        {{ 'btn.details' | translate }}
        %a.pointer.action{ ng: { if: 'createButton && klassName && !disabled', click: 'createItem()' }}
          {{ 'btn.new' | translate }}

{{$ select.selected.object.is_archived}}如果項目已歸檔,則返回true,我不知道如何添加此CSS類! 任何幫助

您可以像這樣使用ng-class指令: ng-class="{'class-false' : selected.object.is_archived, 'class-true' : }" https://docs.angularjs.org/api/ng / directive / ngClass

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM