Is there a way to access a variable declared outside of a promise block within an Angular 6 component?
Consider the following scenario:
items: string[] = [];
ngOnInit() {
const url='SOME URL';
const promise = this.apiService.post(url);
// Response
promise.then(response => {
this.items.push('abc');
this.items.push('def');
});
this.items.forEach(item => {
alert(item);
});
}
I anticipate that the application will display alerts containing the contents of the items array.