angularangular2-universal

TypeError: str.replace is not a function (Angular 2 Universal)


I am using Angular 2 Universal.

I have this line in the html part:

<span [hidden]="!error">{{error}}</span>

It works perfect on the client side, but is shows this error in the terminal (because of server rendering) when the page loads:

Rendering Document Error: TypeError: str.replace is not a function


Solution

  • One walkaround solution is using *ngIf instead of [hidden]:

    <span *ngIf="!!error">{{error}}</span>
    

    This can get rid of

    Rendering Document Error: TypeError: str.replace is not a function

    when server renders.


    BTW, I would be glad to accept another answer if anyone can find a way using [hidden] without error.