2017-10-10 12 views
0

我有一些AngularJS範圍內的項目,我想將它們看作HTML,我發現需要將ngSanitize添加到應用程序中才能執行此操作。所以我說這聲明的索引頁:ngSanitize仍然顯示文本而不是HTML

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

以及App

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> 

還有別的我失蹤了嗎?

回答

1

您正在使用哪個版本的angularjs? ng-bind-html-unsafe已從1.2版本中刪除。如果你想綁定html,你可以使用ng-bind-html。但是你需要在你的角度範圍內使用$sce.trustAsHtml(html)來轉換html字符串。