【问题标题】:Angularjs Html with CSS with in the TAGAngularjs Html with CSS with in the TAG
【发布时间】:2015-08-10 07:45:24
【问题描述】:

我正在尝试使用控制器中的 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>');
};

【问题讨论】:

    标签: javascript css angularjs angular-ui angular-bootstrap


    【解决方案1】:

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

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

    这可能会修复您的代码。

    【讨论】:

    • 没有老板,它不会工作,你什么时候去用户 我们必须使用重复
    猜你喜欢
    • 1970-01-01
    • 2016-02-06
    • 2022-12-02
    • 2015-11-27
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    相关资源
    最近更新 更多