Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

polymer

In AngularJS I would use:

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

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

like image 376
kpg Avatar asked Mar 19 '23 19:03

kpg


2 Answers

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.

like image 131
Dirk Grappendorf Avatar answered Mar 21 '23 09:03

Dirk Grappendorf


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

JSON.stringify(object)
like image 24
Nikos Avatar answered Mar 21 '23 09:03

Nikos