What is the meaning of question mark in expressions in Angular 2?
Edit
Since the original answer, Ecmascript, and Typescript (in 3.7) have both added the ?.
(called the optional chaining operator) operator. See the PR for details.
Original answer
This is not a Typescript operator. Angular 2 has a safe navigation operator in templates.
values?.listArray
is equivalent to
values != null ? values.listArray: null
More info here and here
?
"Question Mark" is not a ternary operator in typescript,
?
is used for safe loading the HTML doc while a component is generating the document for browser display.
If we write list?.values
, it means that if list.values
is non-null, then it will show, and if list.values
is null, it will not show. In any case, it will load the corresponding HTML part without any error.
In summery, it avoids null exception.If values object have a property named listArray then the value of listArray will set else null will set.