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>

jshtml

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);
    }; 
    

}
                      

簡單點來講就是當參數傳參來解決post

相關文章
相關標籤/搜索