henryhw
henryhw

Reputation: 63

How to render from a html file using Angularjs ng-bind-html

I'm using ng-bind-html to render a html code to my page, but my code is too long. So I put it in a HTML file. How can I do that? This is my HTML and Js controller.My page include this:

<div ng-controller="modalPopup"><div ng-bind-html="renderHtml(message)"></div></div>

JS controller:

angular.module('mainApp', []).
controller('modalPopup', function($scope, $http,$sce) {
    $scope.renderHtml = function(value) {
     return $sce.trustAsHtml(value);
  };
  $scope.message = '';
});

I want to put a big block of code HTML to $scope.message How can I do that. Thanks all :)

Upvotes: 3

Views: 3521

Answers (1)

dfsq
dfsq

Reputation: 193261

If you want to include content from the file into your HTML then you should use ngInclude:

<div ng-controller="modalPopup"><p ng-include="'path/to/file.html'"></p></div>

Upvotes: 1

Related Questions