I'm trying to push an object who come from template into array, but when i push the second object, the first is changed and the objects are duplicated.
I'm trying this:
<div class="modal-body">
<select class="form-control select2-hidden-accessible" [(ngModel)]="userSelected" name="user selec" (change)="selectValorUsuario(userSelected)">
<option *ngFor="let usuario of Usuario" [ngValue]="usuario">{{usuario.nome}}</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="classicModal.hide()"
data-dismiss="modal">Fechar</button>
<button type="button" class="btn btn-primary" id="btnIncluirUnidadeUsuarios"
(click)="adicionarArrUsuario()">Incluir</button>
</div>
than in component:
selectValorUsuario(evt) {
this.nomeUsuarioObj.id = evt.id;
this.nomeUsuarioObj.nome = evt.nome;
this.unidadeUsuarioArr.push(this.nomeUsuarioObj)
console.log(this.unidadeUsuarioArr);
}
but the result is: