Title: Angular templates don't play well with strictNullChecks · Issue #19756 · angular/angular · GitHub
Open Graph Title: Angular templates don't play well with strictNullChecks · Issue #19756 · angular/angular
X Title: Angular templates don't play well with strictNullChecks · Issue #19756 · angular/angular
Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => Please do not submit support request here...
Open Graph Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => P...
X Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request ...
Opengraph URL: https://github.com/angular/angular/issues/19756
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Angular templates don't play well with strictNullChecks","articleBody":"## I'm submitting a...\r\n\u003c!-- Check one of the following options with \"x\" -->\r\n\u003cpre>\u003ccode>\r\n[ ] Regression (a behavior that used to work and stopped working in a new release)\r\n[ ] Bug report \u003c!-- Please search GitHub for a similar issue or PR before submitting -->\r\n[x] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n\u003c/code>\u003c/pre>\r\n\r\n**Current behavior:**\r\nCurrently if Typescript has strictNullChecks=true then it is very hard to work with variables that are nullable.\r\n\r\nFor example, if I have: hero?: Hero; inside my HeroDetailComponent class from the Heroes tutorial, then\r\n\r\n```\r\n\u003cng-container *ngIf=\"hero; else no_hero\">\r\n\t\t\u003ch2>{{hero.name}} details!\u003c/h2>\r\n\t\t\u003cinput ([hero])=\"hero.name\" placeholder=\"name\"/>\r\n\u003c/ng-container>\r\n```\r\n\r\nThen there will be an error for hero.name as it might be null and the binding won't work.\r\n\r\n**Expected / new behavior:**\r\n\r\nThe template engine should be able to determine that the variable hero is not null within the if statement and so both of the components above should work. Alternatively, it could add syntax to allow you to explicitly cast a variable to a more specific type that would pass this information further into the template.\r\n\r\n**Minimal reproduction of the problem with instructions:**\r\n\r\nOpen up the Heroes demo and change hero to a nullable variable and add strictNullChecks into tsconfig.json\r\n\r\n**AngularJS version:** 4.4.4\r\n\r\n**Browser:** Chrome 61\r\n\r\n**Anything else:**\r\nCurrent workaround:\r\n\r\n```\r\n\u003cng-container *ngIf=\"hero; else no_hero; let HERO\">\r\n\t\t\u003ch2>{{HERO.name}} details!\u003c/h2>\r\n\t\t\u003cinput [ngModel]=\"HERO.name\" (ngModelChange)=\"HERO.name=$event\" placeholder=\"name\"/>\r\n\t\u003c/ng-container>\r\n```","author":{"url":"https://github.com/Casebash","@type":"Person","name":"Casebash"},"datePublished":"2017-10-17T09:50:32Z","url":"https://github.com/angular/angular/issues/19756"}
| 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:742a47d3-6b4a-a6cd-6a08-19ebc0161355 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D616:172B92:318D8BE:4208D45:6B01EE58 |
| html-safe-nonce | 6b7e561cdfc09614e54acc3791ff5157fa8896c560131c269731651185cf831a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjE2OjE3MkI5MjozMThEOEJFOjQyMDhENDU6NkIwMUVFNTgiLCJ2aXNpdG9yX2lkIjoiMzA4Nzk4OTA3NzEwMjk0NzkyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cdb9e9313f827ab247a94e0d8814b10ad7037074ddd5f38e9d5bd001e61e3f51 |
| hovercard-subject-tag | issue:266060950 |
| 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/19756/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2901f9455c0aa2b5fbbfb200c505f9bde46d69c5865c4aba93ce0b5b6ce7e1be/angular/angular/issues/19756 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2901f9455c0aa2b5fbbfb200c505f9bde46d69c5865c4aba93ce0b5b6ce7e1be/angular/angular/issues/19756 |
| og:image:alt | I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => P... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Casebash |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width