0

I have this in a template:

<div>{{String(element.elementId)}}</div>

but I get this error:

TableBasicExample.html:6 ERROR TypeError: _co.String is not a function
    at Object.eval [as updateRenderer] (TableBasicExample.html:6)
    at Object.debugUpdateRenderer [as updateRenderer] (core.js:14727)
    at checkAndUpdateView (core.js:13841)
    at callViewAction (core.js:14187)
    at execEmbeddedViewsAction (core.js:14145)
    at checkAndUpdateView (core.js:13837)
    at callViewAction (core.js:14187)
    at execComponentViewsAction (core.js:14119)
    at checkAndUpdateView (core.js:13842)
    at callViewAction (core.js:14187)

what I want to do is display the string literal "null" if element.elementId is null, or display "undefined" if element.elementId is undefined, how do I do that?

1 Answers1

0

Try this ternary out:

<div>{{ element.elementId ? String(element.elementId) : "undefined or null"}}</div>

Why do you need to know the if it's null vs undefined? It slightly complicates the check but it can certainly be done.

Devan Buggay
  • 2,717
  • 4
  • 26
  • 35
  • oh that is so nasty, but it might be the only way –  Jan 14 '18 at 23:10
  • 1
    At the time the data in `element` is being hydrated you can do this check in order to remove it from your view code. Do you mind editing the question with that part of your code? – Devan Buggay Jan 14 '18 at 23:11
  • 1
    yeah, I will call String() in the JavaScript instead of the HTML, good idea –  Jan 14 '18 at 23:15
  • 1
    You can also do the check for `null` and `undefined` there as well. Here is a good answer explaining how to check for them as they both resolve to `false`. https://stackoverflow.com/questions/5076944/what-is-the-difference-between-null-and-undefined-in-javascript – Devan Buggay Jan 14 '18 at 23:17