Title: Angular Element issue with change detection running on Property value change · Issue #31055 · angular/angular · GitHub
Open Graph Title: Angular Element issue with change detection running on Property value change · Issue #31055 · angular/angular
X Title: Angular Element issue with change detection running on Property value change · Issue #31055 · angular/angular
Description: 🐞 bug report Affected Package The issue is caused by package @angular/elements Is this a regression? Unknown Description In an Angular Element hosted by a JQuery project, if JQuery tries to set the value of a property defined with the @i...
Open Graph Description: 🐞 bug report Affected Package The issue is caused by package @angular/elements Is this a regression? Unknown Description In an Angular Element hosted by a JQuery project, if JQuery tries to set the...
X Description: 🐞 bug report Affected Package The issue is caused by package @angular/elements Is this a regression? Unknown Description In an Angular Element hosted by a JQuery project, if JQuery tries to set the...
Opengraph URL: https://github.com/angular/angular/issues/31055
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Angular Element issue with change detection running on Property value change","articleBody":"# 🐞 bug report\r\n\r\n### Affected Package\r\nThe issue is caused by package @angular/elements\r\n\r\n### Is this a regression?\r\nUnknown\r\n\r\n### Description\r\nIn an Angular Element hosted by a JQuery project, if JQuery tries to set the value of a property defined with the @Input() decorator, the Angular Element does not see the value change.\r\n\r\n## 🔬 Minimal Reproduction\r\nSteps for a minimal reproduction:\r\n1. `ng new PropBindingTest` (No Routing, Use CSS)\r\n2. `cd PropBindingTest`\r\n3. `ng add @angular/elements`\r\n4. `ng add ngx-build-plus`\r\n5. Change app.module.ts\r\n```\r\nimport { Injector, NgModule } from '@angular/core';\r\n\r\nimport { AppComponent } from './app.component';\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { createCustomElement } from '@angular/elements';\r\n\r\n@NgModule({\r\n declarations: [\r\n AppComponent\r\n ],\r\n imports: [\r\n BrowserModule\r\n ],\r\n entryComponents: [\r\n AppComponent\r\n ]\r\n})\r\nexport class AppModule {\r\n constructor(private injector: Injector) {\r\n }\r\n\r\n ngDoBootstrap() {\r\n const customEl = createCustomElement(AppComponent, { injector: this.injector });\r\n customElements.define('prop-binding-test', customEl);\r\n }\r\n}\r\n```\r\n\r\n6. Change app.component.ts\r\n```\r\nimport { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';\r\n\r\n@Component({\r\n templateUrl: './app.component.html',\r\n styleUrls: ['./app.component.css']\r\n})\r\nexport class AppComponent implements OnInit, OnChanges {\r\n @Input() public testProp: { header: string, paragraph: string };\r\n\r\n public ngOnInit(): void {\r\n console.log('ngOnInit Fired.', this.testProp);\r\n }\r\n\r\n public ngOnChanges(changes: SimpleChanges): void {\r\n console.log('ngOnChanges Fired.', changes, this.testProp);\r\n }\r\n}\r\n```\r\n\r\n7. Change app.component.html\r\n```\r\n\u003ch1 *ngIf=\"testProp\">{{testProp.header}}\u003c/h1>\r\n\u003cp *ngIf=\"testProp\">{{testProp.paragraph}}\u003c/p>\r\n```\r\n\r\n8. Remove `import 'zone.js/dist/zone';` from polyfills.ts, final polyfills.ts should be empty\r\n9. Add `import 'zone.js';` to top of main.ts, final main.ts should be\r\n```\r\nimport 'zone.js';\r\n\r\nimport { AppModule } from './app/app.module';\r\nimport { enableProdMode } from '@angular/core';\r\nimport { environment } from './environments/environment';\r\nimport { platformBrowserDynamic } from '@angular/platform-browser-dynamic';\r\n\r\nif (environment.production) {\r\n enableProdMode();\r\n}\r\n\r\nplatformBrowserDynamic().bootstrapModule(AppModule)\r\n .catch(err => console.error(err));\r\n```\r\n\r\n10. Change tsconfig.json target from 'es5' to 'es2015', final tsconfig.json should look like\r\n```\r\n{\r\n \"compileOnSave\": false,\r\n \"compilerOptions\": {\r\n \"baseUrl\": \"./\",\r\n \"outDir\": \"./dist/out-tsc\",\r\n \"sourceMap\": true,\r\n \"declaration\": false,\r\n \"module\": \"es2015\",\r\n \"moduleResolution\": \"node\",\r\n \"emitDecoratorMetadata\": true,\r\n \"experimentalDecorators\": true,\r\n \"importHelpers\": true,\r\n \"target\": \"es2015\",\r\n \"typeRoots\": [\r\n \"node_modules/@types\"\r\n ],\r\n \"lib\": [\r\n \"es2018\",\r\n \"dom\"\r\n ]\r\n }\r\n}\r\n```\r\n\r\n11. `ng build --prod --single-bundle` (the single-bundle option comes from ngx-build-plus)\r\n12. Copy & Paste PropBindingTest/dist/PropBindingTest/main.d80c1f431a277f0798b0.js into a jQuery project folder\r\n13. In JQuery application, add the following\r\n```\r\n jQuery('head').append('\u003cscript src=\"../assets/main.d80c1f431a277f0798b0.js\">\u003c/script>');\r\n const propTest = document.createElement(\"prop-binding-test\");\r\n jQuery('#some_location').after(propTest);\r\n propTest.testProp = { header: \"I Hope This Works\", paragraph: \"This is very exciting.\" };\r\n```\r\n14. Run your jQuery app, and open your console. You should see `ngOnInit Fired. undefined` as the only printed line, and your custom component should exist in the DOM but display nothing, as `propTest` was never set. If you take a look at the code in app.component.ts, this means that ngOnChanges is never actually running, otherwise we should see another log statement `ngOnChanges Fired.`, which we don't. You can also add `console.dir(propTest);` and see that `testProp` IS being set on the HTMLElement, it just doesn't propagate to the Angular. \r\n\r\nIf I am missing something, can someone please point me towards the proper documentation? I found it very difficult to find good information on the process of creating an Angular Element and hosting it in a non-angular application.\r\n\r\ndependencies from final package.json are: \r\n```\r\n \"dependencies\": {\r\n \"@angular/animations\": \"~7.2.0\",\r\n \"@angular/common\": \"~7.2.0\",\r\n \"@angular/compiler\": \"~7.2.0\",\r\n \"@angular/core\": \"~7.2.0\",\r\n \"@angular/elements\": \"^7.2.15\",\r\n \"@angular/forms\": \"~7.2.0\",\r\n \"@angular/platform-browser\": \"~7.2.0\",\r\n \"@angular/platform-browser-dynamic\": \"~7.2.0\",\r\n \"@angular/router\": \"~7.2.0\",\r\n \"core-js\": \"^2.5.4\",\r\n \"document-register-element\": \"^1.7.2\",\r\n \"ngx-build-plus\": \"^7.8.3\",\r\n \"rxjs\": \"~6.3.3\",\r\n \"tslib\": \"^1.9.0\",\r\n \"zone.js\": \"~0.8.26\"\r\n }\r\n```\r\n","author":{"url":"https://github.com/CollinGraf314","@type":"Person","name":"CollinGraf314"},"datePublished":"2019-06-14T15:14:53Z","url":"https://github.com/angular/angular/issues/31055"}
| 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:46d0311a-56a0-2423-d2c3-2f4366e8e362 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D5F8:29AEE8:1192FFC:177504A:6B011B98 |
| html-safe-nonce | 9d59b3578af230d4140233757d9000c2b519eb4b38e32ff9d91b8a58ef835153 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUY4OjI5QUVFODoxMTkyRkZDOjE3NzUwNEE6NkIwMTFCOTgiLCJ2aXNpdG9yX2lkIjoiNTkzMDIwNzE3MDExMjA2ODUwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 78a0c2fff7e2e70c5dee28a65066a7afba160eb80fae826510d49c3c05567b7d |
| hovercard-subject-tag | issue:456300831 |
| 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/31055/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53aec124d22ec626869114d0fd5f37027d7b27091cfdfb54811803048873ecfc/angular/angular/issues/31055 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53aec124d22ec626869114d0fd5f37027d7b27091cfdfb54811803048873ecfc/angular/angular/issues/31055 |
| og:image:alt | 🐞 bug report Affected Package The issue is caused by package @angular/elements Is this a regression? Unknown Description In an Angular Element hosted by a JQuery project, if JQuery tries to set the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CollinGraf314 |
| 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