Title: Safe navigation operator executes members after "?." even if not needed · Issue #9850 · angular/angular · GitHub
Open Graph Title: Safe navigation operator executes members after "?." even if not needed · Issue #9850 · angular/angular
X Title: Safe navigation operator executes members after "?." even if not needed · Issue #9850 · angular/angular
Description: I'm submitting a ... (check one with "x") bug report feature request support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question Current behavior Safe ...
Open Graph Description: I'm submitting a ... (check one with "x") bug report feature request support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIB...
X Description: I'm submitting a ... (check one with "x") bug report feature request support request => Please do not submit support request here, instead see https://github.com/angular/angular/bl...
Mail addresses
notifications@github.com
Opengraph URL: https://github.com/angular/angular/issues/9850
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Safe navigation operator executes members after \"?.\" even if not needed","articleBody":"**I'm submitting a ...** (check one with \"x\")\n- [x] bug report\n- [ ] feature request\n- [ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\n\n**Current behavior**\nSafe navigation operator can be used to prevent Angular from throwing errors, when trying to access object properties of objects that don't exist.\n\nE.g.\n\n```\n{{ contact?.name }}\n```\n\nOnly evaluates `name` when `contact` is not `null` or `undefined`. This comes in handy when `contact` is something that is loaded asynchronously.\n\nHowever, let's say we have another object on `contact`\n\n```\ncontact: {\n name: 'foo',\n address: {\n street: 'bar'\n }\n}\n```\n\nIf we want to access `street` in the template even though, `contact` is loaded asynchronously, we can use the safe navigation operator for that. **But** we need to apply it on **every nested property** because Angular doesn't ignore the rest of an expression after a `?.`.\n\nHere's what we need to do to render `street`, even though, `address` is synchronous:\n\n```\n{{ contact?.address?.street }}\n```\n\n**Expected/desired behavior**\n\nAngular should ignore member accesses after `?.` inside expressions when the thing before the `?.` is `null` or `undefined`. Or, in code, we should be able to simply do:\n\n```\n{{ contact?.address.street }}\n```\n\n**Reproduction of the problem**\nPlunk: http://plnkr.co/edit/TaoC2w0sSx1izwiqAoJQ?p=preview\n\n**Please tell us about your environment:**\n- **Angular version:** 2.0.0-rc.4\n- **Browser:** all \n- **Language:** TypeScript 1.9 \n","author":{"url":"https://github.com/0x-r4bbit","@type":"Person","name":"0x-r4bbit"},"datePublished":"2016-07-06T18:19:13Z","url":"https://github.com/angular/angular/issues/9850"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:28d42876-37b2-b579-9148-74aaef3458a0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A47C:28815B:173ED68:1EE1457:6B013F98 |
| html-safe-nonce | 658a08b109f9b018efaf27c43ab90c48f62b23d2266a9c06681abea3139b8104 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDdDOjI4ODE1QjoxNzNFRDY4OjFFRTE0NTc6NkIwMTNGOTgiLCJ2aXNpdG9yX2lkIjoiMzE1Njk1ODE0Mjk3ODQwODM0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dd99f20c9bb817cccc276b05fcf508940b51c07ae901d78616b4516ac5388bb5 |
| hovercard-subject-tag | issue:164141015 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/9850/issue_layout |
| twitter:image | https://opengraph.githubassets.com/db98e405a979c717324bf8e129d7e38692b18f58c18a24247543297e050dada6/angular/angular/issues/9850 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/db98e405a979c717324bf8e129d7e38692b18f58c18a24247543297e050dada6/angular/angular/issues/9850 |
| og:image:alt | I'm submitting a ... (check one with "x") bug report feature request support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIB... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 0x-r4bbit |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width