Skip to content Skip to sidebar Skip to footer

Angular Ts Error Ts1109

i get following error in console: webpack: Compiling... 10% building modules 0/1 modules 1 active ...p/shoppinglist2/src/app/app.module.tsERROR in src/app/meal.service.ts(46,

Solution 1:

You are calling generic method in wrong way so that you get this -

ERROR in src/app/meal.service.ts(46,56): error TS1109: Expression expected

Wrong way

catchError(this.handleError('getMeals', <Meals>)) // Line 46: the Error

Correct way

catchError(this.handleError<Meals>('getMeals'))

 getMeals (page:number): Observable<Meals> {
    let httpParams = new HttpParams().set('where', '%')
      .set('orderBy', 'meal_id')
      .set('page', page.toString())
      .set('items', '10');
    //this.messageService.add('Debug: ' + httpParams);returnthis.http.get<Meals>(this.mealUrl, { params: httpParams  })
      .pipe(
        tap(meals => this.log(`fetched ${meals.count} entries`)),
        catchError(this.handleError<Meals>('getMeals')) // Line 46: the Error
      );
  };

Solution 2:

if you check the handleError function in the documentation that you refered to, you will notice it's expecting to receive a parameter,

private handleError<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {

  // TODO: send the error to remote logging infrastructureconsole.error(error); // log to console instead// TODO: better job of transforming error for user consumptionthis.log(`${operation} failed: ${error.message}`);

  // Let the app keep running by returning an empty result.returnof(result as T);
 };
}

But in your code, you are using the handleError function wrong.

getMeals (page:number): Observable<Meals> {
    let httpParams = new HttpParams().set('where', '%')
      .set('orderBy', 'meal_id')
      .set('page', page.toString())
      .set('items', '10');
    //this.messageService.add('Debug: ' + httpParams);returnthis.http.get<Meals>(this.mealUrl, { params: httpParams  })
      .pipe(
        tap(meals => this.log(`fetched ${meals.count} entries`)),
        catchError(this.handleError('getMeals', <Meals>)) // Line 46: the Error
      );
  };

That's why you get this - ERROR in src/app/meal.service.ts(46,56): error TS1109: Expression expected. So try this -

catchError(this.handleError< Meals >('getMeals'))

Hope that helps.

Post a Comment for "Angular Ts Error Ts1109"