Angular 2 个模板 - 方法的安全导航运算符
Angular 2 templates -Safe navigation operator for methods
我正在使用 angular 2 安全导航运算符 成功地用于属性,文档指出它用于 属性 路径,但是 方法路径的最佳方法是什么?
myObj?.myMethod().myProperty
给出异常:
EXCEPTION: TypeError: Cannot read property 'myProperty' of null in
[{{myObj?.myMethod().myProperty}}
在javascript中,引自w3schools:
A JavaScript method is a property containing a function definition.
我看不出有任何问题为什么它不能像这样工作:
{{myObj?.myMethod()?.myProperty}}
<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
我正在使用 angular 2 安全导航运算符 成功地用于属性,文档指出它用于 属性 路径,但是 方法路径的最佳方法是什么?
myObj?.myMethod().myProperty
给出异常:
EXCEPTION: TypeError: Cannot read property 'myProperty' of null in [{{myObj?.myMethod().myProperty}}
在javascript中,引自w3schools:
A JavaScript method is a property containing a function definition.
我看不出有任何问题为什么它不能像这样工作:
{{myObj?.myMethod()?.myProperty}}
<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