angular2 template - ngSwitchWhen doesn't work when duplicate whens are written -
i learning angular2 using ng-book2 book , playing around built in directives. reading ngswitch
, stumbled upon feature can write multiple ngswitchwhen
same conditions following code:
<ul [ngswitch]="choice"> <li *ngswitchwhen="1">first choice</li> <li *ngswitchwhen="2">second choice</li> <li *ngswitchwhen="3">third choice</li> <li *ngswitchwhen="4">fourth choice</li> <li *ngswitchwhen="2">second choice, again</li> <li *ngswitchdefault>default choice</li> </ul>
which output following result:
second choice
second choice, again
i wrote code below:
<div [ngswitch]="myvar"> <div *ngswitchwhen="myvar==1">my var 1</div> <div *ngswitchwhen="myvar==2">my var 2</div> <div *ngswitchwhen="myvar==3">my var 3</div> <div *ngswitchwhen="myvar==3">special feature of ng swtich</div> <div *ngswitchdefault>my var {{myvar}}</div> </div>
which not print output same conditions. thought code proper when saw *ngswitchwhen="myvar==3" found out mistake.
but strangely works except repeated conditions
is there difference between these 2 conditions?
*ngswitchwhen="2"
*ngswitchwhen="myvar==3"
which 1 use?
ngswitchwhen="2"
this expression checks value of switchcase against variable myvar(myvar=="6")
ngswitchwhen="myvar==3"
whereas expression evaluates myvar==(myvar==2) value inside parantheses return 1 if myvar 2 , 0 if not
Comments
Post a Comment