I want to compare id.here if id equals 5 do this, else do that. How can I achieve this?
<div class="case" data-ng-if="data.id === '5' "> <input type="checkbox" id="{{data.id}}" value="{{data.displayName}}" data-ng-model="customizationCntrl.check[data.id1]" data-ng-checked="{{data.status}}=='1'" onclick="return false;">{{data.displayName}} <br> </div> <div class="case" data-ng-else> <input type="checkbox" id="{{data.id}}" value="{{data.displayName}}" data-ng-model="customizationCntrl.check[data.id]" data-ng-checked="{{data.status}}=='1'">{{data.displayName}}<br> </div>
ng-if is better in this regard. Using it in place of ng-show will prevent the heavy content from being rendered in the first place if the expression is false. However, its strength is also its weakness, because if the user hides the chart and then shows it again, the content is rendered from scratch each time.
ngIf is a structural directive, which means that you can add it to any element like div , p , h1 , component selector, etc. Like all structural directive, it is prefixed with * asterisk. We bind the *ngIf to an expression (a condition in the above example). The expression is then evaluated by the ngIf directive.
A shorthand form of the directive, *ngIf="condition" , is generally used, provided as an attribute of the anchor element for the inserted template. Angular expands this into a more explicit version, in which the anchor element is contained in an <ng-template> element.
Use ng-switch with expression and ng-switch-when
for matching expression value:
<div ng-switch="data.id"> <div ng-switch-when="5">...</div> <div ng-switch-default>...</div> </div>
Example is here
Angular2 example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With