I'm using the angular 2 safe navigation operator successfully for properties, which the documentation states is for property paths, but what is the best approach for methods paths?
myObj?.myMethod().myProperty
gives the Exception:
EXCEPTION: TypeError: Cannot read property 'myProperty' of null in [{{myObj?.myMethod().myProperty}}
In javascript, quote from w3schools:
A JavaScript method is a property containing a function definition.
I don't see any problems why it shouldn't work like this:
{{myObj?.myMethod()?.myProperty}}
From Angular.io cheat sheet:
<p>Employer: {{employer?.companyName}}</p>
The safe navigation operator (?) means that the employer field is optional and if undefined, the rest of the expression should be ignored
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With