/**
* @input {any} The value of the option
*/
@Input()
get value() {
if (isPresent(this._value)) {
return this._value;
}
return this.text;
}
set value(val: any) {
this._value = val;
}
i don’t really know, what isPresent(val) does, but i think it checks if value !== null, so it returns text() which is: return this._elementRef.nativeElement.textContent;
and not null
EDIT:
here is what isPresent(val) does: export const isPresent = (val: any) => val !== undefined && val !== null;
This is the behavior similar to that Angular 2 had until version 2.2.1. When the value was null binding a string like “{0: null}” to the model instead of an actual null object.
But since version 2.2.1 of Angular 2 it is possible to send null value using [ngValue] = “null”.
So I did the post wondering if there was any similar solution using Ionic 2.
Any updates on this ?
It seems that it is still not possible to do that with angular-ionic@3.3.0.
As per the docs “If ion-option is not given a value attribute then it will use its text as the value”.
So if you set [value]=“null” it will set the model to whatever you set as the ion-option text node element, kinda sad though since it works with a basic select and ngValue.