javascript - Not Getting Expected Result in Negative Case with *ngIf in Angular 2 App -


in angular2 app printing view data in table layout. 1 section of our data array of flags. right i'm using combination of *ngfor , *ngif print values view when values exist. working expected code:

    <ng-container *ngfor="let status of record.status">          <td *ngfor="let flag of status.flags">              <span *ngif="flag.flag" class="standard-flag">                  {{flag?.flag}}              </span>             <span *ngif="!flag.flag" class="zero-flags">                 no flags             </span>         </td>       </ng-container> 

now, in case there no data (i.e., empty arrays) i'd print "no flags" screen -- see above. far know, there no "else" functionality prior angular 4 (correct me if i'm wrong). need use *ngif evaluate when case , print 'no flags' screen accordingly.

this proving peculiarly difficult, , i'm not sure why. i've stared @ screen long, , have tried numerous combinations, no avail.

to handle case there no value in "flags", i've tried have now:

<span *ngif="!flag.flag" class="zero-flags"> 

as as:

<span *ngif="flag.flag ===''" class="zero-flags"> 

i don't errors, either correct value printed view, or, if there no value, nothing appears @ (when should appear "no flags"). missing here? how handle desired result? basically, want "no flags" print view in case "flags" empty array 3 objects within "status" array.

for reference, data looks this:

"status": [     {         "reference": "gold",         "flags": []     },     {         "reference": "silver",         "flags": []     },     {         "reference": "bronze",         "flags": [             {                 "flag": "not available",                 "flagtype": "normal"             }     } ], 

if there no flags in status.flags never hit statement prints "no flags". can't iterate empty array. use *ngif check if there flags in status.flags first. if not print "no flags".

<ng-container *ngfor="let status of record.status">     <div *ngif="status.flags.length > 0">         <td *ngfor="let flag of status.flags">              <span *ngif="flag.flag" class="standard-flag">                 {{flag?.flag}}              </span>         </td>     </div>     <div *ngif="status.flags.length < 1">         <td>             <span *ngif="!flag.flag" class="zero-flags">                 no flags             </span>         </td>     </div> </ng-container> 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -