If you're looking to add dynamic content or create elements dynamically, it's best to follow Angular's approach rather than using JavaScript or jQuery.
Angular utilizes the Renderer2 service for DOM manipulation.
To begin, inject the Renderer2 service:
constructor(public ele: ElementRef, private rend:Renderer2)
Next, use a template variable in your element:
<h1 #r> Body content </h1>
Use viewChild
to obtain a reference to your element:
@ViewChild('r') ref:ElementRef;
Finally, create or append data using Renderer2:
this.rend.appendChild(this.ref.nativeElement,text);
For a modified example, see this: https://stackblitz.com/edit/angular-w7eij5-ehqgkz
If you wish to learn more about Renderer, refer to: https://angular.io/api/core/Renderer2