我正在显示一个包含
HTML代码的字符串:
< div style =“font-size:14px”ng-bind =“currentBook.description”>< / div>
当我使用ng-bind和ng-bind-unsafe时,它什么都没显示.
如何解析HTML?
附录
我添加了对sanitize的引用,但是ng-bind和ng-bind-unsafe仍然没有显示任何内容:
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-route.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-sanitize.js"></script>
好的,我添加了ngSanitize var app = angular.module(‘app’,[‘ngSanitize’]);现在它的工作原理.
看起来你错过了ngSanitize请看下面的演示
原文链接:https://www.f2er.com/angularjs/141350.html你可以在这里找到更多
https://docs.angularjs.org/api/ngSanitize/service/ $消毒
var app = angular.module('app',['ngSanitize']); app.controller('firstCtrl',function($scope,$sce) { $scope.currentBook = { description: "<p>some description</p>" }; });
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-sanitize.js"></script> <body ng-app="app"> <div ng-controller="firstCtrl"> <div style="font-size: 14px" ng-bind-html="currentBook.description"></div> </div> </body>