0
Good afternoon, I am in need of making the typescript excute a call every 10 milliseconds.
I gave a search using setInterval but the information comes as Undefined but when I save, the values in this.tags.name
comes as Undefined.
export class InicialComponent implements OnInit {
tagsMongoUrl = 'http://localhost:8080/tags';
tags = [];
tagsSave = new Tags();
msgs: Message[] = [];
nome = '';
valor = '';
constructor(private principalService: PrincipalService, private http: Http) { }
ngOnInit() {
this.pesquisar();
}
pesquisar() {
this.principalService.pesquisar()
.then(() => null);
}
salvar() {
setInterval(function () {
const v = 100;
for (let i = 0; i < v; i++) {
this.tagsSave.name = 'name ' + i;//undefined aqui pois não acessa o objeto
this.tagsSave.value = i.toString();
this.nome = this.tagsSave.name;
this.valor = this.tagsSave.value;
console.log(this.valor);
this.saveData();
}
}, 3000);
}
saveData() {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(this.tagsMongoUrl,
JSON.stringify(this.tagsSave), { headers })
.toPromise()
.then(response => response.json());
}
}