-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed
Description
Feature Request
Problem
While accessing the data from view in template expression, if a null object is used like below :
{{ book }}
View is rendered and displayed value is blank.
Suppose the template expression involves a property path, as in this next example where we’re displaying the name of a null book.
{{ book.name }}
This would throw a null reference error :
TypeError: Cannot read property 'name' of null.
Workaround
We can find a workaround for this using a conditional block like this:
<div v-if="book">
{{ book.name }}
</div>
But if we have a use case where we need a property path deep into the object some thing like this ?
a.b.c.d
Solution
We can use a safe navigation operator ( ?. ) or elvis operator similar to Angular 2. That can help in reducing a lot of conditional tags in a complex code.
chrislandeza, someblue, degrov, dmnBrest, jjzabkar and 60 moreReDreamport, dmnBrest, lehni, AbdallahBedir, Todmy and 14 more
Metadata
Metadata
Assignees
Labels
No labels