Reputation: 2141
This simple code returns null
. I had the expectation that nonNullable
form would have some checks inside. Do you have any idea why it's implemented like this?
I tested it with Angular 18
test = new FormControl('', { nonNullable: true });
// ...
const val: any = null;
this.test.setValue(val);
console.log(this.test.value); // returns null
Upvotes: 0
Views: 37
Reputation: 55699
nonNullable
won't provent you from setting null
but it changes behavior around defaultValue
(also if you mess with the types you're on your own)
See https://angular.dev/api/forms/FormControlOptions#nonNullable
Upvotes: 1