ng-bind-html在ng-repeat中问题的解决办法
<div ng-controller="MyCtrl"> Hello, {{name}}! <div class="row" ng-repeat="post in posts"> <div ng-bind-html="TrustDangerousSnippet(post)"> <p>{{post.post}}</p> </div> </div </div>
js
var myApp = angular.module('myApp',[]); function MyCtrl($scope, $sce) { $scope.name = 'Superhero'; var input_data = []; input_data.push({post: '<h1>bla</h1>'}); $scope.posts = input_data; $scope.TrustDangerousSnippet = function(post) { return $sce.trustAsHtml(post.post); }; }
简单点来说就是当参数传参来解决