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