I need to push data into a global variable when a button is pressed. However, even though i created a local variable to copy the data i want to push, it continues to overwrite the global array (all previous value turn into the most recently pushed one).
global variables:
tjoints = []
- list of joints dictsjoints = {}
- dict of numbers - defined by the user on the web browser
This is my code:
tableAdd(){
if (this.time == undefined) {
this.flashMessage.show('Duração do tempo faltando', {cssClass: 'alert-danger'});
} else if(this.time == 0) {
this.flashMessage.show('Duração precisa ser maior que Zero', {cssClass: 'alert-danger'});
} else {
var temp = this.joints; //----> copy of the global variable
var i = this.tjoints.push(temp); // pushing temp into the global array
this.tjoints[i-1][9] = this.time;
console.log('this.tjoints: ', this.tjoints);
}
}
html:
<a class="btn btn-info" style="display: inline-block (click)="tableAdd()">Add</a>