kpg
kpg

Reputation: 7966

Is there a way to print the json representation of an object to the browser in Polymer?

In AngularJS I would use:

<pre>{{object|json}}</pre>

Is there a way to do the same thing in PolymerJS?

Upvotes: 4

Views: 1269

Answers (2)

Dirk Grappendorf
Dirk Grappendorf

Reputation: 3422

The implementation of a custom json filter is quite simple:

<script>
  PolymerExpressions.prototype.json = function(object) {
    return JSON.stringify(object);
  }
</script>

Then you can use {{object|json}} anywhere you like.

Upvotes: 5

Nikos
Nikos

Reputation: 7552

I don't think so out of the box, you could create a custom element and just render your object as:

JSON.stringify(object)

Upvotes: 2

Related Questions