desperado06
desperado06

Reputation: 406

angular2 error message never disappears

I have a dynamically generated table with select controls on every row. Each row is validated against a custom validator.

The validator is hit and works ok.

When it comes to display the error message according to the result of the validator I cant figure out the exact expression. At the moment ERROR message is always displayed.

enter image description here

I even deleted all validation logic to return null at all times.Still no luck kind regards.

Template:

<tr *ngFor="let kredi of krediList ; let i=index" [attr.rowindex]="i">
   <td>{{kredi?.erkenkapamatutari | number : '1.2-2' }} TL</td>
   <td *ngIf="this.krediHesaplaAktif===true">       
      <select [(ngModel)]="kredi.talepedilenmahsuptipi" class="form-control input-xs" name="mahsuptipleriselect{{i}}" [krediTuruMahsupValidator]="validateKrediTuruMahsup(i)">                          
         <option *ngFor="let m of mahsupTurleri" [ngValue]="m.id" [selected]="kredi.talepedilenmahsuptipi == m.id"  >
            {{m.name}}
         </option>
      </select>
      <p style="color: red" *ngIf="!validateKrediTuruMahsup.valid" class="text-danger"> ERROR MESSAGE</p>
  </td>
  <td><button type="button" class="btn btn-danger btn-sm" (click)="taksitGoruntuleClicked(i)">Taksitleri Gör</button></td>
</tr>

Validation:

validateKrediTuruMahsup(selectedIndex: number) { 
        return <ValidatorFn>((control: FormControl) => {

                return null;       
        });
 }

Upvotes: 1

Views: 49

Answers (1)

eko
eko

Reputation: 40647

Your validateKrediTuruMahsup method is returning null and !null is true. Which makes your *ngIf="true"

Upvotes: 1

Related Questions