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>
View DEMO

6 comments:

  1. Simple but perfect for what I needed. Thanks!

    ReplyDelete
  2. Great for the template way, but how can i do that in the component ts?.

    Thanks

    ReplyDelete
  3. @elpana :

    @ViewChild('myElement') private myElementContainer:ElementRef;

    this.myElementContainer.nativeElement.innerHTML = '';

    add this to your code.

    ReplyDelete
  4. Another disadvantage that some people feel is part https://baccarat.team/ of online casinos also has to do with the lack of physical contact and that disadvantage is the one about money. Some people do not like seeing their money as electronic and not real bills in their hand.

    ReplyDelete
  5. With us, you will no longer have to worry about having neither time to complete the assignment ( https://beekeepclub.com/causes-of-environmental-and-climate-change/ ) nor ideas on how to start writing an essay. We’ve got you covered.

    ReplyDelete

Blogroll

Popular Posts