A
A
Artem00712017-02-02 17:14:47
JavaScript
Artem0071, 2017-02-02 17:14:47

What does "?" mean? in the user?.name entry (question to question ->)?

I saw this code in the manual:

@Component({
    selector: 'my-app',
    template: `<div>
                    <p>Имя пользователя: {{user?.name}}</p>
                    <p>Возраст пользователя: {{user?.age}}</p>
               </div>`,
    providers: [HttpService]
})

Actually it works, but what do these questions mean?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2017-02-02
@Artem0071

Alexander Belov 's answer is not accurate.
There is no check for the presence of name or age, it is checked if user != null, otherwise user cannot contain any parameters at all.
those. user?.name can be "decomposed" into user==null?'':user.name
without this, there will be an error:

user = null
user.name
VM111:1 Uncaught TypeError

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question