【问题标题】:HTML text not rendered in proper way from JSON in MOBILE ANGULAR UI在 MOBILE ANGULAR UI 中,HTML 文本未从 JSON 以正确方式呈现
【发布时间】:2016-02-09 11:09:40
【问题描述】:

我正在使用 MOBILE ANGULAR UI 框架。当我从 JSON 中检索文本(包括标签)时,文本会在 .html 文件中显示带有标签的文本。我看过一个链接,但我没有得到解决方案。这个链接是AngularJS : Insert HTML into view。 我已经安装了 ngsanitize,但是当我包含在 app.js 中时,我的项目没有显示任何想法。

屏幕截图:

App.js

angular.module('Y', [
  'ngRoute',
  'mobile-angular-ui',
  'Y.controllers.Main',
])

控制器:

.controller('chooseProductDescription', function($scope, $http){
    $http({
        method:'get',
        url:'http://www.json-generator.com/api/json/get/cgbdRjMVpe?indent=2',
        header:{'Content-Type':'application/json'},
    }).success(function(data,status,headers, config){   
        $scope.productDescription = data;   
        $scope.html = data;
        $scope.trustedHtml = $sce.trustAsHtml($scope.html);
    }).error(function(data, status,headers, config){

    })
})

ngsanitize 对于文本视图是强制性的吗?但我也试过 ngsanitize,我又看到了一个链接。How to install ngSanitize?

我想为文本视图提供简单的解决方案。

HTML。

<div ng-repeat="cat in productDescription">
        {{cat.product.fullDescription}}
</div>

我多次阅读此链接 (AngularJS : Insert HTML into view) 但直到现在我才得到解决方案。我正在使用移动 Angular ui 框架,可能是它有不同的方法。

我想在 MOBILE ANGULAR UI 的 html 页面中只显示没有标签的文本。 请分享您的想法。

【问题讨论】:

  • 我猜..你没有正确包括ngSanitize..
  • @Minato。当我在 app.js 中包含 ngSanitize 时,我的项目不起作用。
  • 请参阅此plunk 以获得更好的理解。尝试在angular 之后和script 之前包括.. angular-sanitize
  • 你的问题解决了吗..?
  • @Minato。不。我想我正在使用移动角度 ui,那一个有不同的方法.. 但我不确定。

标签: javascript html angularjs json mobile-angular-ui


【解决方案1】:

我猜..你没有正确包含ngSanitize

请参阅此plunk 以更好地理解.. 尝试在angular 之后和script 之前包含.. angular-sanitize

在您的标记

而不是这个{{cat.product.fullDescription}} 使用..

<span ng-bind-html="cat.product.fullDescription"></span>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 2023-03-15
    • 1970-01-01
    • 2012-03-05
    相关资源
    最近更新 更多