2
<ion-item ng-bind-html="renderHtml(word[key])">

</ion-item>

Where word[key] is

<ul>
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
</ul>

CSS:

ul {padding: 1px 10px 1px 20px;list-style-type: upper-roman;}

I have a much more complex structure with css. The CSS works on cordova and react but since i am porting function to ng, the css do not work. Please Advise or point what i am missing here.

1

1 Answer 1

5

You're seeing the angular XSS security in play (see http://errors.angularjs.org/1.2.23/$sce/unsafe).

There are 2 ways to fix this:

  1. If the html is user created/influenced in some way, you will need to include the $sanitize module. Refer to the link above.

  2. If the html is from you only, mark it as trusted HTML using $sce.trustAsHtml. Something like:

angular.module('myapp', []).controller('myctrl', function($scope, $sce) {
  $scope.renderHtml = function(html) {
    return html;
  };
  $scope.word = $sce.trustAsHtml('\
<ul>\
  <li>item 1</li>\
  <li> item 2 </li>\
  <li>item 3</li>\
</ul>');
});
ul {padding: 1px 10px 1px 20px;list-style-type: upper-roman;}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp" ng-controller="myctrl">
  <ion-item ng-bind-html="word"></ion-item>
</div>

Sign up to request clarification or add additional context in comments.

2 Comments

I am already using your 2. method. The issue is <ul> css is not loading. I have checked by adding <ul style="list-style-type: upper-roman;">. Which actually worked, but is an ugly solution. The html elements such as <p><ol> are in separate CSS.
@moeen-ud-Din I've updated my snippet. As you can see, the CSS works perfectly fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.