1

I have below code

  <ion-card >
    <ion-card-content>
      <ion-chip *ngFor="let skill of contact.skills | split">
        <ion-label>{{skill}}</ion-label>
      </ion-chip>
    </ion-card-content>
  </ion-card>

then I want to hide the card if there is no skills, so I changed it to

  <ion-card [hidden]="(contact.skills | split).length == 0">
    <ion-card-content>
      <ion-chip *ngFor="let skill of contact.skills | split">
        <ion-label>{{skill}}</ion-label>
      </ion-chip>
    </ion-card-content>
  </ion-card>

and it's working fine, but the problem is value is going to split pipe twice, then how can I define a variable and using pipe once?

I tried below but not working

  <ion-card #skills="contact.skills | split" [hidden]="skills.length == 0">
    <ion-card-content>
      <ion-chip *ngFor="let skill of skills">
        <ion-label>{{skill}}</ion-label>
      </ion-chip>
    </ion-card-content>
  </ion-card>

1 Answer 1

1

You can't use template variables to assign custom values.

Template variables can only be used to refer to elements and components directly or by name (exportAs) or to assign values from a structural directives context like let idx=index in *ngFor

For your use case create a field in the components class instead and bind to this class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.