I have a block of else-if conditions in my ASP.NET MVC Razor page like this
if(condition1 && condition2 || condition3)
{ //Some HTML elements }
else if(condition4 || condition5)
{ //Some HTML elements }
else if(condition6 || condition7)
{ //Some HTML elements }
else
{ //Some HTML elements }
I want to write same conditions in AngularJs. I tried to do this as
<div ng-if="condition1 && condition2 || condition3">
</div>
<div ng-if="condition4 || condition5">
</div>
<div ng-if="condition6 || condition7">
</div>
How can I write else block? Remember Condition 1 ~ 7 are too complex to draw else.
But I tried this, which I thought should work, but it is not working. I used ng-init and set a model with name elseClause. Then in following divs, I check if it doesn't have value of 1 (means previous div is not initiated).
<div ng-if="condition1 && condition2 || condition3" ng-init="elseClause = 1">
</div>
<div ng-if="(condition4 || condition5) && elseClause != 1" ng-init="elseClause = 1">
</div>
<div ng-if="(condition6 || condition7) && elseClause != 1" ng-init="elseClause = 1">
<span> This is in second last div </span>
</div>
<!-- Else Block -->
<div ng-if="elseClause != 1">
<span> This is else block </span>
</div>
But the problem is, the second last div (in my scenario) is initiated and prints <span> This is in second last div </span> and also it prints <span> This is else block </span>. It sets value 1 to elseClause but when it comes to second block, it doesn't carry that value.
Why is it happening?
Aucun commentaire:
Enregistrer un commentaire