首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngSanitize仍然显示文本而不是HTML

ngSanitize仍然显示文本而不是HTML
EN

Stack Overflow用户
提问于 2017-10-10 08:11:18
回答 1查看 28关注 0票数 0

我想将AngularJS作用域上的一些内容作为HTML,我发现需要将ngSanitize添加到应用程序中才能做到这一点。因此,我将其添加到索引页的声明中:

代码语言:javascript
复制
<script src="Scripts/angular-sanitize.min.js"></script>

并将此包括在应用程序中

代码语言:javascript
复制
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标记中:

代码语言:javascript
复制
<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>

还有什么东西我遗漏了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-10 08:31:28

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46661675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档