javascript - AngularJS: ngBindHtml that also contains child bindings? -
this question has answer here:
- angularjs ng-bind-html 2way data binding 2 answers
angularjs v1.3.14: currently, i'm using 'ngsanitize' module in angular app "ng-bind-html" bind html output of area on page. works , doesn't require older $sce 'trust html' stuff.
but, i'd embed child bindings within html.
so... works...
angular.module('myapp', ['ngsanitize'...) .controller('somectrl', ['$scope', function($scope) { $scope.myhtml = '<p>hello world</p>'; }]); ... <div ng-app="myapp" ng-controller="somectrl" ng-bind-html="myhtml"></div>
something doesn't...
angular.module('myapp', ['ngsanitize'...) .controller('somectrl', ['$scope', function($scope) { $scope.mycontent = 'hello world'; $scope.myhtml = '<p>{{mycontent}}</p>'; }]); ... <div ng-app="myapp" ng-controller="somectrl" ng-bind-html="myhtml"></div>
thoughts?
a simple directive it:
<div bindy="myhtml"></div>
.directive('bindy', function($compile) { return { link: function($scope, $element, $attrs) { var html = $scope.$eval($attrs.bindy); $element.html(html); $compile($element.contents())($scope); } }; });
Comments
Post a Comment