Angular filtering HTML tags with $SCE services

Source: Internet
Author: User

Angular JS is one of the strengths of his data two-way binding this cow B function, we will often use two things is the Ng-bind and the Ng-model for the form. However, in our project we will encounter this situation, the data returned in the background with a variety of HTML tags. For angular 1.2, we have to use the $SCE service to solve our problems. It can be done by using $sce.trustashtml (). This method converts the value to be accepted by the privilege and is safe to use "ng-bind-html".

1. Controller (' Healtheducationdetailctrl ', [' $sce ', ' $scope ', ' Storage ', ' $state ', ' homeservice ', ' $stateParams ', ' $ Ionictabsdelegate ',2     function($sce, $scope, Storage, $state, Homeservice, $stateParams, $ionicTabsDelegate) {3$scope. $on (' $ionicView. Beforeenter ',function() {4         //Close all tab tabs5$ionicTabsDelegate. Showbar (false);6       });7 8       //Guaranteed Health Education Details page can display the respective title9$scope. title=$stateParams. Article_title;Ten       varArticle_id=$stateParams. article_id; One       varparam={article_id:article_id}; A homeservice.gethealtharticledetail (param); -       //Load Health Education details -$scope. healtharticledetail=[]; the$scope. $on (' Homeservice.gethealtharticledetail ',function(event, data) { -$scope. healtharticledetail=data; -         //Richtextreplace is parsing HTML identifiers -         //$scope. Trusthtml=storage.richtextreplace ($scope. healtharticledetail.article_contents); +$scope. trusthtml= $sce. trustashtml($scope. healtharticledetail.article_contents); -       }) +  A$scope. $on (' $ionicView. Beforeleave ',function() { at         //Open all tab tabs -$ionicTabsDelegate. Showbar (true); -       }); -}])

HTML code:

1 <ion-view view-title= "{{title}}" ng-view-title= "title" >2   <ion-content >3      <div style= "width:100%; padding:10px 15px;" >4       ng-bind-html= "trusthtml"></div>5     </div>6   </ion-content>7 </ion-view>

Angular filtering HTML tags with $SCE services

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.