When I click on a button on my page, an event fires, and dynamically updates the DOM if there is relative content.
But I want to be able to clear the DOM when the button is clicked again, and then provide the results. Clicking again currently just adds more and more content, which is no good.
I've been trying to do this in Angular, and have been having trouble.
my template
<div class="container">
<div class="row">
<div class="articles-container" #element>
<div class="article" *ngFor="let article of allMatches">
<div class="article-image"> <img src="{{article.image}}" alt=""> </div>
<div class="title-wrapper">
<div class="article-info">
<a href="{{article.url}}"> <h3> {{ article.title }} </h3> </a>
<div class="article-description"> {{ article.description }} </div>
</div>
<div class="source-wrapper">
<div class="article-thumb"> <img src="{{article.thumbnail}}" alt=""> </div>
<div class="article-source"> {{ article.source }} </div>
</div>
</div>
</div>
</div>
</div>
I've been trying to grab the #element tag, and using jQuery to see if it is empty or not. But it just breaks the app.
i.e.
// if ($("#element").is(':empty)') ) {
//
// console.log("empty");
// }
I'm trying to do this at the very top of my function (the one fired when the button is clicked), so it checks if the div has content or not, and if it does, empty it, then provide the new content.
I've read using jQuery is discouraged in Angular2. What is the better way?