You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
createComponent function example not work on 16.2.1 #51492
const componentRef = [createComponent](https://angular.io/api/core/createComponent)(HelloComponent, {host, environmentInjector});
host was change to hostElement, should become this
const componentRef = [createComponent](https://angular.io/api/core/createComponent)(HelloComponent, {hostElement, environmentInjector});
Btw it just not work.
Please provide a link to a minimal reproduction of the bug
NG0912: Component ID generation collision detected. Components 'HelloComponent' and 'HelloComponent' with selector 'hello-component' generated the same component ID. To fix this, you can change the selector of one of those components or add an extra host attribute to force a different ID. Find more at https://angular.io/errors/NG0912
Please provide the environment you discovered this bug in (run ng version)
@hiepxanh thanks for creating a repro. The problem is that you've used a binding value that would always be different for each change detection cycle, i.e. <div [innerHTML]="domSanitizer.bypassSecurityTrustHtml(content)"></div>. The bypassSecurityTrustHtml would return a new object each time it's invoked. You can try adding a new property to a class that would store a reference to the function call result and use it in a template instead. For example:
@Component({
standalone: true,
selector: 'my-app',
template: `<div [innerHTML]="sanitizedContent"></div>`,
})
export class AppComponent {
domSanitizer = inject(DomSanitizer);
content = `<h1> hello world 1</h1>
<dynamic1> </dynamic1>
<dynamic2> </dynamic2>
<h1> hello world 2</h1>`;
// Store a reference to the computed result and use it in a template
sanitizedContent = this.domSanitizer.bypassSecurityTrustHtml(this.content);
Hello sir, hope you are doing well. @AndrewKushnir I think this may be my last issue about this problem. I can have a perfect reproduction on our issue. I created on a new issue here: #51535
Activity
[-]createComponent function example not work[/-][+]createComponent function example not work on 16.2.1[/+]JeanMeche commentedon Aug 24, 2023
FYI it's missing a CD cycle.
Calling
componentRef.changeDetectorRef.detectChanges();fixes your issue.hiepxanh commentedon Aug 24, 2023
@JeanMeche I just try to copy the document to make sure it follow tutorial. it's still not work sir, I updated as your suggest but it still the same
JeanMeche commentedon Aug 24, 2023
You're missing
import 'zone.js'. (bootstrapApplication()throws silently an NG908)hiepxanh commentedon Aug 24, 2023
aw great, finally it start running. Thank you sir @JeanMeche
hiepxanh commentedon Aug 24, 2023
I created PR to update this
hiepxanh commentedon Aug 24, 2023
anyway, lazy is so bad, that repo is not complex enough. I think the current situation should look like this example repo:
https://codesandbox.io/p/sandbox/relaxed-feather-27fv8y?file=/src/app/app.component.ts:63,6
@JeanMeche
refer from this issue: #51491
hiepxanh commentedon Aug 24, 2023
the dynamic 1 and dynamic 2 should jump to here, and I already use change detection to update it:
hiepxanh commentedon Aug 27, 2023
copy from #51491 (comment)
dynamic1 can render successful with variable reference instead of function because it's new object everytime
solve the issue I'm facing now.
I will add an example about this in the document
hiepxanh commentedon Aug 28, 2023
Hello sir, hope you are doing well. @AndrewKushnir I think this may be my last issue about this problem. I can have a perfect reproduction on our issue. I created on a new issue here: #51535
angular-automatic-lock-bot commentedon Oct 3, 2023
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.