<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); }; }
简单点来说就是当参数传参来解决
时间: 2024-11-26 08:57:25