-4

AngularJS code:

$scope.checking="<div style="color:red;">check</div>";

HTML code:

{{checking}}

Result in HTML page in browser:

<div>check</div>

Now what I want is that the $scope.checking variable be parsed in HTML as if it's a tag I defined.

So the result in html page should be:

check

and the above should come in red color

Any way to do it? hopefully its simple... AngularJS experts please help!

i got the output but the string doesnt come in red! the style tag is ignored! how can i do it? do i use interpolate?

5
  • Did you declare ng-model="checking"? I am a little confused on what you are asking. Commented Apr 24, 2016 at 17:46
  • angularjs and evrything works fine...evrything is declared and angularjs perfectly.... Commented Apr 24, 2016 at 17:50
  • Perhaps you can post a line from your Code. This would be helpful. Commented Apr 24, 2016 at 17:51
  • Possible duplicate of Angular - Interpolate string with html Commented Apr 24, 2016 at 17:53
  • 2
    why would you do something like that with n number of ways available to counter anything as such? Commented Apr 24, 2016 at 17:56

1 Answer 1

1

Use ng-bind-html! Here is the docs-page for ng-bind-html. This will help you.

https://docs.angularjs.org/api/ng/directive/ngBindHtml

ng-bind-html will render your html-string in the browser. Perhaps you have to "trust" your html string like here: http://erikaugust.com/thoughts/ng-bind-html/

1
  • I think he just wants to print out the value of checking. Commented Apr 24, 2016 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.