You also can create some directives to manage your validator.
HTML :
<input type="number" maxNumber="999"[(ngModel)]="element.orderItemNewCredit" #newCredit="ngModel">
<div *ngIf="newCredit.errors && (newCredit.dirty || newCredit.touched)" class="alert alert-danger">
<div [hidden]="!newCredit.errors.maxNumber">New credit cannot be superior than 999/div>
</div>
Directive : maxNumberValidator.directive.ts
import {Directive, Input} from '@angular/core';
import {AbstractControl, NG_VALIDATORS, ValidationErrors, Validator} from "@angular/forms";
@Directive({
selector: '[maxNumber]',
providers: [{provide: NG_VALIDATORS, useExisting: MaxNumberValidatorDirective, multi: true}]
})
export class MaxNumberValidatorDirective implements Validator {
@Input() maxNumber: number;
constructor() { }
validate(control: AbstractControl): ValidationErrors {
return control.value <= this.maxNumber ? null : { maxNumber: { valid: false } };
}
}
And do not forget to add this directive into your module file.
Validatorsclass to perform validation, you will need to write custom validators. Pleast post more code so I can see the way you perform validation.