Title: Show more details with the ExpressionChangedAfterItHasBeenCheckedError warning · Issue #18970 · angular/angular · GitHub
Open Graph Title: Show more details with the ExpressionChangedAfterItHasBeenCheckedError warning · Issue #18970 · angular/angular
X Title: Show more details with the ExpressionChangedAfterItHasBeenCheckedError warning · Issue #18970 · 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/18970
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Show more details with the ExpressionChangedAfterItHasBeenCheckedError warning","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\nThe current warning message `ExpressionChangedAfterItHasBeenCheckedError` is telling us what are the values before and after the change detection, but there aren't enough information to help to debug.\r\n\r\nWe are never sure what object or property is referring to. Also, the lines are not always reliable.\r\n\r\nIn some cases, we use an array of objects and messages like so are provided:\r\n```\r\nERROR Error: ExpressionChangedAfterItHasBeenCheckedError: \r\nExpression has changed after it was checked. \r\nPrevious value: 'undefined'. Current value: '[object Object],[object Object]'.\r\n at viewDebugError (errors.ts:30)\r\n at expressionChangedAfterItHasBeenCheckedError (errors.ts:29)\r\n at checkBindingNoChanges (util.ts:145)\r\n at checkNoChangesNodeInline (view.ts:477)\r\n at checkNoChangesNode (view.ts:568)\r\n at debugCheckNoChangesNode (services.ts:557)\r\n at debugCheckDirectivesFn (services.ts:466)\r\n at Object.View_App_0._co [as updateDirectives] (App.html:7)\r\n at Object.debugUpdateDirectives [as updateDirectives] (services.ts:443)\r\n at checkNoChangesView (view.ts:378)\r\n```\r\n\r\nI can see the file name is `(App.html:7)`, so I presume is something in my template, but it's not clear what it is. Also, note that my bug should be on line 2 (`\u003cdiv *ngIf=\"testObject\">`), and not on **line 7** as mentioned by angular.\r\n\r\n## Expected behavior\r\nPerhaps, it would be nice adding to the warning message the property/object that has changed its value.\r\n\r\nI would expect the warning message being something like so, instead:\r\n```\r\nERROR Error: ExpressionChangedAfterItHasBeenCheckedError: \r\nExpression has changed after it was checked. \r\nPrevious testObject value: 'undefined'. Current testObject value: '[{a: 1, b: 2}, {a: 3, b: 4}]'.\r\n```\r\n> PS: note the `testObject` key from my App class, also the values from object as string.\r\n\r\n**In that case, it would be easier to debug that the object is `testObject`;**\r\n\r\n## Minimal reproduction of the problem with instructions\r\nThis plunker can give an example of the context provided by angular. http://plnkr.co/edit/mX6REf9oidrVeURCvTZG?p=preview\r\n\r\n> This plunker is a fork from @adrienboulle from #14748 (comment)\r\n\r\n```ts\r\n@Component({\r\n selector: 'my-app',\r\n template: `\r\n \u003cdiv>\r\n \u003cdiv *ngIf=\"testObject\">\r\n Object exists\r\n \u003c/div>\r\n \u003cdiv class=\"image-container\"\r\n [ngStyle]=\"{\r\n 'height': getHeightPx()\r\n }\">\r\n \u003cimg alt=\"image\" style=\"height: 100%\" [src]=\"getUrl()\"/>\r\n \r\n \u003c/div>\r\n \u003c/div>\r\n `,\r\n})\r\nexport class App implements AfterViewInit {\r\n img: Image;\r\n isLoaded: boolean = false;\r\n testObject: any;\r\n\r\n constructor(private elementRef: ElementRef) {}\r\n\r\n public ngAfterViewInit(): void {\r\n this.img = this.elementRef.nativeElement.querySelector('img');\r\n this.isLoaded = true\r\n \r\n this.testObject = [{a: 1, b: 2}, {a: 3, b: 4}];\r\n }\r\n\r\n public getUrl(): string {\r\n return 'https://angular.io/resources/images/logos/angular2/angular.png';\r\n }\r\n \r\n public getHeightPx(): string {\r\n if (!this.isLoaded)\r\n return '0px';\r\n\r\n return '100px';\r\n }\r\n}\r\n```\r\n\r\nIf you comment line 33: `// this.testObject = [{a: 1, b: 2}, {a: 3, b: 4}];`, you will end up with another bug with the same issue, but now, referring to the `getHeightPx()` method which was pointed by @adrienboulle on the issue #14748.\r\n\r\n```\r\nApp.html:9 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: \r\nExpression has changed after it was checked. Previous value: '0px'. Current value: '100px'.\r\n```\r\n\r\nIn that case, it's much easier to debug. The line 9 is correct.\r\nAlso, because of its values (`'0px'` and `'100px'`), it is easier to find the property. However, the message error could have the missing `getHeightPx()` method which would make the debugging easier.\r\n\r\n\r\n## What is the motivation / use case for changing the behavior?\r\n\u003c!-- Describe the motivation or the concrete use case. -->\r\nMake it easier to debug this popular error #18129 #17887 #17572 #15464 #14748 and many other issues.\r\n\r\n## Environment\r\n\r\n```\r\nAngular version: 4.3.6\r\n```\r\n\r\n","author":{"url":"https://github.com/leocaseiro","@type":"Person","name":"leocaseiro"},"datePublished":"2017-08-31T07:57:38Z","url":"https://github.com/angular/angular/issues/18970"}
| 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:456da4d4-6917-c8ba-4820-168678914df5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B380:1F44:1220C2A:17BDC38:6B013FD5 |
| html-safe-nonce | 873c4138fc13947f1d8790ae4e15b71da23d60b9462149949635a32d42c80936 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzgwOjFGNDQ6MTIyMEMyQToxN0JEQzM4OjZCMDEzRkQ1IiwidmlzaXRvcl9pZCI6IjQ1MTIyOTE1MzQ4NzEyODE2MjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 15f261dade87f076351503cd520f16d138ebfc516df1f5da082416faaa50c133 |
| hovercard-subject-tag | issue:254247909 |
| 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/18970/issue_layout |
| twitter:image | https://opengraph.githubassets.com/70747a20fa4298a986fe4a65fcf7a3b7e2891bc8b221c4c2237888b5ae31a6b5/angular/angular/issues/18970 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/70747a20fa4298a986fe4a65fcf7a3b7e2891bc8b221c4c2237888b5ae31a6b5/angular/angular/issues/18970 |
| 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 | leocaseiro |
| 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