1

i have following list:

<ion-list>
    <ion-item ng-repeat="item in productlistitems">
       {{ item.name }}!
    </ion-item>
</ion-list>

item.name is with HTML tags, but they appear as plain text.

How can I achieve that the HTML code gets "executed"?

3
  • Check your console you have an error it stopped processing the page (most likely) Commented Jun 22, 2016 at 16:47
  • There is no error in the console. Commented Jun 22, 2016 at 16:48
  • answer below is likely correct I overlooked the part about it being HTML. Believe if it's just a string literal then $sce isn't necessary but if the HTML comes from a service or otherwise isn't a literal the $sce is needed. Commented Jun 22, 2016 at 16:59

1 Answer 1

2

In order to render HTML, use the "ng-bind-html" directive like this:

<div ng-bind-html="item.name"></div>

In your controller, you need to "trust" the data using the $sce service like this:

$scope.item.name = $sce.trustAsHtml("your HTML here");
Sign up to request clarification or add additional context in comments.

4 Comments

But I use ng-repeat and can't set this for every item? Or am I stupid now.. I'm setting the items like this in app.js: $scope.productlistitems = currentProducts;
The link I provided to the $sce service has an example using ng-repeat. I'll try to edit my answer soon.
I can give you a better answer if you show what the HTML you're trying to render looks like.
Ah I didn't see the link. Perfect. The example behind the link was great now it works.Thanks.

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.