how can bind string values to html controls in angularJS

For Example in asp.net with c# we build string like

string str="<div>..in that tag we can use any type of controls..</div>";

we can bind the string as htmlgenericController, so is there any option like above in angularjs?

Upvotes: 0

Views: 164

Answers (1)

pgrodrigues
pgrodrigues

Reputation: 2078

Yes it is, there is an example in AngularJS Documentation:

Controller:

angular.module('bindHtmlExample', ['ngSanitize'])
   .controller('ExampleController', ['$scope', function($scope) {
       $scope.myHTML = 'I am an <code>HTML</code>string with ' + '<a href="#">links!</a> and other <em>stuff</em>';
}]);

HTML:

<div ng-controller="ExampleController">
    <p ng-bind-html="myHTML"></p>
</div>

Output:

<div ng-controller="ExampleController">
    <p>I am an <code>HTML</code>string with ' + '<a href="#">links!</a> and other <em>stuff</em></p>
</div>

Upvotes: 2

Related Questions