Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

angularjs

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 :)

like image 528
henryhw Avatar asked Dec 05 '25 07:12

henryhw


1 Answers

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>
like image 145
dfsq Avatar answered Dec 07 '25 21:12

dfsq