Reputation: 1
I had written below code could anyone help how to get Promise instead of ZoneAwarePromise
MyFunction(): Promise < any > () {
let promise = new Promise((resolve) => {
if (this.domainServerCache
&& (this.domainServerCache.domainFqdn === selectedFqdn)) {
resolve(this.domainServerCache);
} else if (selectedFqdn) {
const url = `drarest/domains/get?domainFqdn=${selectedFqdn}`;
this.http.post < any > (url, something).toPromise().then(
(resp) => {
console.log('result', resp);
this.loadDomainSubject
.next(resp.domain.domainAdminsGroupPath);
this.domainServerCache = {
'domainFqdn': selectedFqdn,
...resp
};
this.loadDomainSubject.complete();
resolve(this.domainServerCache);
}
);
}
});
console.log(promise);
return promise;
}
Upvotes: 0
Views: 405
Reputation: 79
I think there is a better way to rewrite this
MyFunction() {
return new Promise((resolve) => {
if (this.domainServerCache && (this.domainServerCache.domainFqdn === selectedFqdn)) {
resolve(this.domainServerCache);
} else if (selectedFqdn) {
const url = `drarest/domains/get?domainFqdn=${selectedFqdn}`;
this.http.post<any>(url, something).toPromise().then(
(resp) => {
console.log('result', resp);
this.loadDomainSubject.next(resp.domain.domainAdminsGroupPath);
this.domainServerCache = {'domainFqdn': selectedFqdn, ...resp};
this.loadDomainSubject.complete();
resolve(this.domainServerCache);
}
);
}
})
}
Upvotes: 1