Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of question mark in expressions in Angular 2?

What does values?.listArray mean here? Specifically I am interested in the question mark.

[inputValue] = "values?.listArray" 
like image 584
crystal_test Avatar asked Aug 28 '17 15:08

crystal_test


People also ask

What does a question mark mean in react?

“Question mark” or “conditional” operator in JavaScript is a ternary operator that has three operands. The expression consists of three operands: the condition, value if true and value if false.

What does question mark do in TypeScript?

The question mark ? in typescript is used in two ways: To mention that a particular variable is optional. To pre-check if a member variable is present for an object.

What does ?: Mean in TypeScript?

What does ?: mean in TypeScript? Using a question mark followed by a colon ( ?: ) means a property is optional. That said, a property can either have a value based on the type defined or its value can be undefined .

What does 2 question marks mean in TypeScript?

Double question marks(??) or nullish coalescing operator helps us to assign default values to null or undefined variables in Angular and Typescript. It's often called as Null coalescing operator. It's introduced as part of Typescript 3.7 version.


1 Answers

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

like image 50
Titian Cernicova-Dragomir Avatar answered Sep 29 '22 03:09

Titian Cernicova-Dragomir