Category : promise

i am expecting a string return for the giver code but it is returning ZoneAwarePromise¬† in service getCoveredPeriod() { let loanDetails = this.getLoanDetails().toPromise(); loanDetails.then((res: any) => { const coveredPeriodStart = new Date( res.coveredperiodstartdate ).toLocaleDateString(‘en-US’, { year: ‘numeric’, month: ‘long’, day: ‘numeric’, }); const coveredPeriodEnd = new Date( res.coveredperiodenddate ).toLocaleDateString(‘en-US’, { year: ‘numeric’, month: ‘long’, day: ..

Read more

Just switched to JavaScript recently. I want to fetch list data from an API (i.e ["string1","string2"…]). Coded the below: var listData = []; const getListData = function (){ const Url = ‘http://localhost:8081/api/v1/getList’; if(listData.length === 0){ let temp = fetch(Url).then(data => data.json()); listData = temp; } return listData; }; var testArr = []; console.log(‘List Initial:’,listData); testArr ..

Read more

I am having trouble passing variables through to my Angular data handling service My app runs a query to get the number of a slide SERVICE getAudience() { return this.firestore.collection(‘sessions’).doc(‘operaHouse’).collection(‘questions’, ref=>ref.where("isApproved", "==", true).orderBy("queueOrderNumber", "asc").limit(1)) } COMPONENT getSlideNum = () => this.qandaService.getAudience().snapshotChanges().subscribe(res =>(this.slideNum = res[0].payload.doc.data().answerNum)) this returns this.slidenum to the component When I then send this.slidenum ..

Read more

I have this service that calls to an API to get a bunch of movie descriptions and returns an Observable: getNowPlayingMovies$(page: number, country?: string): Observable<NowPlaying> { console.log(`${this.baseUrl}${this.now_playing}?${this.key}&region=${country || ‘US’}&page=${page}`); return this.http.get<NowPlaying>( `${this.baseUrl}${this.now_playing}?${this.key}&region=${country || ‘US’}&page=${page}` ); } On the component that uses this function above I call it changing every time the page value so I ..

Read more

I used to do async/await and just learned to use Observable in Angular because it’s the Angular way, so I want to refactor this code snippet here to make this as an Observable: async refreshToken() { const headers = this.authStorage.getRequestHeader(); const body = { refreshToken: this.authStorage.getStoredValue(‘refreshToken’), }; const newAccessToken = await this.http .post<any>(ApiURLStore.REFRESH_TOKEN_URL, body, { ..

Read more

In my Angular I have a service that draws a picture on a canvas ang get its "ImageData". This is my service.ts: getColorArray (movie: MovieDb): Observable<any> { var img = new Image(); img.crossOrigin = "Anonymous"; img.src = "https://www.themoviedb.org/t/p/w342/" + movie.poster; var canvas = <HTMLCanvasElement>document.getElementById("canvas"); var ctx = canvas.getContext("2d"); canvas.height = 50; canvas.width = 30; ctx.clearRect(0, ..

Read more