Angularjs the way to output HTML via $SCE _angularjs

Source: Internet
Author: User
Tags html tags

"Problem description"

One of the Angularjs's strengths is his data-two-way binding capabilities-----> ng-bind and for Formng-model

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

When Angularjs output HTML, browsers do not parse these HTML tags

Through the API, it is found that ng-bind-html the output of HTML is realized through instruction.

 
 

But it doesn't work, and the HTML code is displayed in the browser.

"Solution"

It was later discovered that the HTML display was also required through the $SCE service.

Angular.module ("list", []). Controller ("Bloglistctrl", Bloglistctrl). Filter ( 
 ' to_trusted ', [' $sce ', function ($ SCE) {return 
  function (text) {return 
   $sce. trustashtml (text) 
  } 
 }] 

Here, a filter is built through $SCE to filter out the HTML of the output.

 
 

This allows the normal output of HTML tags via angularjs, and is parsed by the browser

Summary

The above is the entire content of this article, I hope that the content of this article for everyone's study or work to bring certain help, if you have questions you can message exchange.

Related Article

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.