Angularjs Html with CSS with in the TAG

Angularjs Html with CSS with in the TAG

本文关键字:with the TAG in CSS Html Angularjs      更新时间:2023-09-26

我试图在控制器中使用ng-bind-html属性和$sce依赖项在模板中插入HTML。但由于某些原因,它没有像预期的那样工作,它不能显示国家国旗。我能够检查和看到的标志代码值即将到来,但旗帜不能在下拉菜单中显示,当我在我的项目实施提前感谢。我的代码:

在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}" >