Hello. In my project I’m iterating through an array of objects in a template using repeat.for, but the type of displayed value can vary - it can be either string, number or boolean, so I want to either straight up display it (${elem.value}
) or use my custom element, which is basically a checkbox. That’s why I wanted to use typeof
to check the variable type, but it doesn’t return anything (${typeof(elem.value)}
doesn’t display anything so typeof(elem.value) === 'boolean'
is always false) or just throws an error (when I’m not using parentheses, like this: typeof elem.value
). Of course I can create a method in my view model, like isBoolean(value)
and it would work, but it would be basically wrapper for what I wanted to use in my template. If anything, I’d rather use lodash, but it would be an unused import in my .ts file. Is there a more elegant way to achieve what I want? Here’s my code for context.
<div repeat.for="elem of item" class="col-md-12">
<my-checkbox if.bind="typeof(elem.value) === 'boolean'" checked.bind="elem.value" disabled.bind="true">
</my-checkbox>
<span else>${elem.value}</span>
</div>