2

Is there an existing angular filter for making JSON data appear as formatted HTML?

JSON data from a controller:

{ data: 'This data is <b>bold</b>' }

HTML:

<div>{{data | someKindOfFormatFilter }}</div>

Wanted result:

This data is bold

7
  • you want to bind HTML with filter right? Commented Nov 23, 2015 at 8:07
  • Use ng-bind-html like <div ng-bind-html='data'></div> Commented Nov 23, 2015 at 8:07
  • you can use ng-style and ng-class directive Commented Nov 23, 2015 at 8:08
  • @SameerK ng-bind-html gives me an error: Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context. Commented Nov 23, 2015 at 8:25
  • 1
    Take a look at the last 2 answers here stackoverflow.com/questions/19770156/… to fix the issue. Commented Nov 23, 2015 at 9:03

1 Answer 1

1

I ended up doing as SameerK suggested, to use ngSanitize and ng-bind-html

var app = angular.module('app', ['ngSanitize']);

Answered in this post: How to output html through AngularJS template?

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

Comments

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.