I was working in angular2 and was curious to know whether I could use ngSwitch to load <div>
tag when variable is of certain datatype.i.e.
something like this:
<div [ng-switch]="value">
<p *ng-switch-when="isObject(value)">This is Object</p>
<p *ng-switch-when="isArray(value)">This is Array</p>
<p *ng-switch-when="isBoolean(value)">This is Boolean</p>
<p *ng-switch-when="isNumber(value)">This is Number</p>
<p *ng-switch-default>This is Simple Text !</p>
</div>
is this possible to load the div
tag when variable is of certain datatype?
if not, any workaround for this?
An alternative would be to use
ngIf
:Yes, you can do it but now directly in template. Just create a method in controller to check for a type:
Working Plunker
Please update your Angular to RC version first.