Home > Net >  Angular - operations on html with directives?
Angular - operations on html with directives?

Time:01-06

<ul >
      {{
        <li *ngFor="let element of addedElements">{{element.amount}} {{element.title}}</li>
        ??
        "No element added yet"
      }}
</ul>

Is this possible in some way?

I want to check if any li element is made, if not write "No element added yet"

CodePudding user response:

Wrap your message in an element, and only show it if there are no elements, so

<li *ngIf="addedElements.length == 0">No elems yet"</li>

CodePudding user response:

You can check if addedElements has lenght. If not, just render span using ngIf <span *ngIf="!addedElements.lenght>No element added yet</span>

CodePudding user response:

An idea...

 <li *ngIf="elements.length > 0"; else NotElements>

....
           
<ng-template #NotElements>
   <label> Not elements </label>
</ng-template>

:)

  •  Tags:  
  • Related