Typescript .length return undefined
Try Like these
String(control.value).length != 5
OR
control.value.toString().length != 5
I think that the type of your input isn't string but number.
@Component({
selector: 'my-app',
template: `
<div>
<input type="number" [ngFormControl]="ctrl">
</div>
`
})
export class AppComponent {
constructor() {
this.ctrl = new Control();
this.ctrl.valueChanges.subscribe((val) => {
console.log(val.length);
});
}
}
In this case val.length
returns undefined
since numbers don't have a length
attribute.
See this plunkr for more details: https://plnkr.co/edit/5yp5ms9XY5Z3TEE2qYIh?p=preview.