Angular1 provides angular.element by to create JavaScript element. In Angular2, It is much easy, you can define element by using #<element name> as attribute
Markup to define element
<div #myElement> sample text in div </div>
Emptying Element
You can empty element by using making whole inner HTML as null. Find below markup
<button (click)="myElement.innerHTML = ''">Empty div</button>
Remove Element
You can remove element by using .remove()
<button (click)="myElement.remove()">Empty div</button>
Simple but perfect for what I needed. Thanks!
ReplyDeleteGreat for the template way, but how can i do that in the component ts?.
ReplyDeleteThanks
@elpana :
ReplyDelete@ViewChild('myElement') private myElementContainer:ElementRef;
this.myElementContainer.nativeElement.innerHTML = '';
add this to your code.
Nice!
ReplyDelete