"AngularJs"---$sce output html

Source: Internet
Author: User

"Problem description"

One of the great strengths of angular JS is his data bidirectional binding function----->ng-bind and the Ng-model for the form

But in our project we will encounter this situation, the data returned in the background with a variety of HTML tags

The browser does not parse these HTML tags when angularjs output html

We use instructions such as ng-bind-html to bind, the browser is displayed in the HTML code

"Solution---$sce"

By using $ sce.trustashtml (). This method converts the value to be accepted by the privilege and is safe to use "ng-bind-html"

We can also use this as a filter that can be called at any time on the template.

Filter Code:

App.filter (' to_trusted ', [' $sce ', function ($SCE) {return function (text) {    return $sce. trustashtml (text); };}]);

HTML code:

<ng-bind-html= "currentwork.description | to_trusted"></p  >

"AngularJs"---$sce output html

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.