繁体   English   中英

ngSanitize仍显示文本而不是HTML

[英]ngSanitize still displaying text instead of HTML

我想将AngularJS范围中的一些项目显示为HTML,我发现需要将ngSanitize添加到应用程序中才能执行此操作。 因此,我将此添加到索引页上的声明中:

<script src="Scripts/angular-sanitize.min.js"></script>

并将其包含在应用程序中

var app = angular.module("HtJobPortal", ["LocalStorageModule", "ngSanitize"]);
var serviceBase = "http://htauth.htcsol.local:65200/";
var resourceBase = "http://localhost:50915/";
(function () {
   "use strict";

    app.constant("ngAuthSettings", {
        apiServiceBaseUri: serviceBase,
        apiResourceBaseUri: resourceBase,
        clientId: "TMS_Portal"
    });
    app.config(function ($httpProvider) {
        $httpProvider.interceptors.push("authInterceptorService");
    });
    app.run(["authService", function (authService) {
        authService.fillAuthData();
    }]);

})();

然后将'ng'属性添加到我想以HTML格式显示的标签中:

<div class="panel-body">
    <div class="col-lg-3 module text-center" ng-bind-html-unsafe="html">
        Jobs Module <br />
        {{settings.jobs}}
    </div>
    <div class="col-lg-3 module text-center" ng-bind-html-unsafe="html">
        Warehouse Module <br />
        {{settings.warehouse}}
    </div>
    <div class="col-lg-3 module text-center" ng-bind-html-unsafe="html">
        Stock Module <br />
        {{settings.stock}}
    </div>
    <div class="col-lg-3 module text-center" ng-bind-html-unsafe="html">
        Tracking Module <br />
        {{settings.tracking}}
    </div>
</div>

还有其他我想念的东西吗?

您正在使用哪个版本的angularjs? ng-bind-html-unsafe已从1.2版本中删除。 如果要绑定html,可以使用ng-bind-html 但是您需要在角度范围内使用$sce.trustAsHtml(html)转换html字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM