Answer the question
In order to leave comments, you need to log in
How to achieve asynchrony?
There is a function:
getSome() {
this.http.get('/some')
.subscribe( (data: Array<object>)=> {
console.log(data)
this.AllMaterial = data; // не делает запрос
}, err => {
console.log(err)
})
}
second() {
if (this.isEmpty(this.AllMaterial)) {
this.getSome();
}
console.log(this.AllMaterial)
}
Answer the question
In order to leave comments, you need to log in
async getSome() {
const data = await this.http.get('/some').toPromise();
console.log(data)
return data;
}
async second() {
if (this.isEmpty(this.AllMaterial)) {
this.AllMaterial = await this.getSome()
}
console.log(this.AllMaterial)
}
Well, like this
getSome() {
return this.http.get('/some')
}
second() {
if (this.isEmpty(this.AllMaterial)) {
this.getSome().subscribe( (data: Array<object>)=> {
console.log(data)
this.AllMaterial = data; // не делает запрос
console.log(this.AllMaterial)
}, err => {
console.log(err)
})
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question