Home > Mobile >  How do I remove an attribute (directive) dependent on whether something exists?
How do I remove an attribute (directive) dependent on whether something exists?

Time:01-20

I want to remove [tooltip] if the value given for the text does not exist.

<ng-template #lSelector [formGroup]="form">
  <selectorf
    
    formControlName="label"
    [tooltip]="this.form.controls.l.value"
  >
  </selectorf>

if "this.form.controls.l.value" is null, remove tooltip.

CodePudding user response:

You could do this,

[tooltip]="this.form.controls.l.value ? this.form.controls.l.value : null"

CodePudding user response:

It is not an elegant solution but could you use an *ngIf like this:

<ng-template #lSelector [formGroup]="form">
  <selectorf *ngIf="this.form.controls.l.value"
    
    formControlName="label"
    [tooltip]="this.form.controls.l.value"
  >
  </selectorf>
   <selectorf *ngIf="!this.form.controls.l.value"
    
    formControlName="label"
  >
  </selectorf>

  • Related