Angular 2 json prettify print filter .replace error
<p>Found this solution to do a pretty print of JSON in the HTML however I'm getting <code>.replace</code> error. I'm not seeing any thing wrong with the code unless I'm being blind.</p>

<p>error: <code>TypeError: Cannot read property 'replace' of undefined</code></p>

<pre><code>@Pipe({
  name: 'prettyprint'
})
export class PrettyPrintPipe {
   transform(val) {
    return JSON.stringify(val, null, 2)
      .replace(' ', '&amp;nbsp;')
      .replace('\n', '&lt;br/&gt;');
  }
}
</code></pre>

<p>Hmm that didn't seems to do its job, thought it'd pretty print it but it added <code>/</code> instead.</p>

<p><a href="https://i.stack.imgur.com/qA7OB.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/qA7OB.jpg" alt="enter image description here"></a></p>