I've noticed that @Input setter in a Directive is not initially called when in the template a value of an empty string ("") is provided. But when the value of "null" or "false" is provided, the setter method is called.
Why is that?
As far as I've read, an empty string is a falsy value in JS, so why passing an empty string does not work as "null" or "false"? Is it a feature?
DIRECTIVE:
@Directive({
selector: '[myInputDir]'
})
export class ExampleDirectiveClass {
@Input('myInputDir') public set valFromMyInput(value: string) {
if (value) {
this._inputVal = value;
} else {
this._inputVal = 'setUpVal';
}
}
(... rest of the class)
}
HTML
(...)
<input
[myInputDir]="">
</input>
(...)