Angularjs HTML content in an expression, how it is not escaped, directly represented as an HTML element

Source: Internet
Author: User

In the template, directly:

Direct use in Ionic:

<p class= "Contentwen" ng-bind-html= "detial.content" ></p>//translated HTML

By default, ANGULARJS will escape any HTML tags in the interpolation instruction job expression (model), such as the following model:
$scope. msg = "hello,<b>world</b>!"
<p>{{msg}}</p>
The rendering process escapes the B-tags, and their meetings are displayed in plain text rather than as markers;
The interpolation instruction escapes any HTML content in the model in order to prevent HTML injection attacks.
If for some reason the model containing the HTML tag is to be used and rendered by the browser, you can use the Ng-bind-html-unsafe directive to turn off the default HTML tag escape:
<p ng-bind-html-unsafe= "MSG" ></p>;

Using the NG-BIND-HTML-UNSAFE directive requires extreme caution, and it should be limited to HTML tags that you fully trust and control.

ANGULARJS also has an instruction, ng-bind-html, which can selectively purify the HTML tag, while allowing other tags to be interpreted by the browser, using the following:

Method One:
1. Import Angular-sanitize.js
2. The modules that the press needs to rely on in your app are as follows:

var app = angular. module (' myApp ', [' ngsanitize ']);

3.<p ng-bind-html= "MSG" ></p>;

Method Two:

1. Import Angular-sanitize.js
2. Use it as a filter:

Angular.module (' myApp '). Filter (' to_trusted ', [' $sce ', function($sce) { return function(text) { return $sce. trustashtml (text);};}]);

3.<p ng-bind-html= "MSG | To_trusted "></p>;

Angularjs HTML content in an expression, how it is not escaped, directly represented as an HTML element

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.