Any ideas why this bind isn't working?
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.myHTML = "<a href='#'>a link</a>";
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="MyCtrl">
<p ng-bind-html="myHTML"></p>
</div>
For the HTML binding to work, your module needs to have ngSanitize
injected as well as the file angular-sanitize(.min).js
included.
var myApp = angular.module('myApp',['ngSanitize']);
function MyCtrl($scope) {
$scope.myHTML = "<a href='#'>a link</a>";
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-sanitize.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<p ng-bind-html="myHTML"></p>
</div>
Or you can use String Contextual Escaping (which will probably be the way to do it in future versions of Angular).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With