簡體   English   中英

帶有CSS的Angularjs HTML在TAG中

[英]Angularjs Html with CSS with in the TAG

我正在嘗試在控制器中使用ng-bind-html屬性和$ sce依賴項將HTML插入模板內。 但是由於某種原因,它無法按預期工作,因此無法顯示國家/地區標志。 我可以檢查並看到標志代碼值即將到來,但是當我在My Project中實施時,標志無法在下拉列表中顯示。 我的代碼:

在HTML中

<ui-select ng-model="payment.baseCurrency"  name="baseCurrency" class="currency" required data-ng-change="determinePaymentMethods()" theme="select2" >
                    <ui-select-match placeholder="{{'Select' | translate}}"><flag country="{{$select.selected.flagCode}}" size="16"></flag> {{$select.selected.code}} {{$select.selected.name}}
                    </ui-select-match>
                    <ui-select-choices repeat="baseCurrency in baseCurrencies track by baseCurrency.flagCode | searchFilter:{name:$select.search}" >
                      <flag country="baseCurrency.flagCode" size="16"   ng-bind-html=" toTrusted($index) +' '+ baseCurrency.code +' '+ baseCurrency.name |highlight: $select.search"></flag>
                    </ui-select-choices>
                  </ui-select>

在控制器中

$scope.toTrusted = function(length) {
    var country = $scope.baseCurrencies[length].flagCode;
    return $sce.trustAsHtml('<span class="flag '+country+'"></span>');
};

ui-select-choices行中,您需要使用ng-repeat而不是repeat

<ui-select-choices ng-repeat="baseCurrency in baseCurrencies track by baseCurrency.flagCode | searchFilter:{name:$select.search}" >

那可能會修復您的代碼。

暫無
暫無

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

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