Use ng-bind-html label Considerations __html

Source: Internet
Author: User

In Angularjs, when you want to render the background text with HTML tags, use ng-bind-html instead of ng-bind, you can normally use the HTML tag you want to use. Note, however, that if you use a symbol in the text, be aware that you want to escape the symbol.


Examples of the use of 1>ng-bind-html:

index.html

<div ng-controller= "Examplecontroller" >
 <p ng-bind-html= "myhtml" ></p>
</div>


Protractor.js

It (' Should check ng-bind-html ', function () {
  expect (element (by.binding (' myhtml ')). GetText ()). Tobe (
      ' I am an ' Htmlstring with links! and other stuff ');


script.js

Angular.module (' bindhtmlexample ', [' ngsanitize '])
  . Controller (' Examplecontroller ', [' $scope ', function ($scope {
    $scope. myhtml =
       ' I am ' <code>html</code>string with ' +
       ' <a href= ' # ' >links!</a > and other <em>stuff</em> ';
}];




Result: <a href= "#" >links!</a> and other <em>stuff</em> were parsed

Effect Chart:



But note that if you use the symbol in the text, note that you want to escape the symbol

such as: (1) greater than symbol (>)---> &gt;

(2) less than sign (<)---> &lt;

Otherwise system error:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.