When clicking on a button, an element with the class of emails
should be cloned.
HTML:
<form id="add-user">
<div class="email-container">
<div class="emails">
<mat-form-field class="email full-width">
<input matInput class="email-field" type="email" required placeholder="E-Mail">
</mat-form-field>
</div>
</div>
<i class="material-icons icon" id="addEmailField" (click)="clone()">add_box</i>
</form>
TS:
public clone(): void {
const clone = document.querySelector('.emails').cloneNode(true); // clone the selector .emails
document.querySelector('.email-container').appendChild(clone); // append it to .email-container
}
The cloning part works but the problem is the placeholder of the cloned element. If I type something into the text field, it won't disappear.
This is how it looks if I type into a cloned element:
What am I doing wrong? Run and test it here.