1
votes

how to solve this problem anybody help me.

using Angular 5

My angular method:

list.component.ts file

 ngOnInit() {
       this.getUserdata(1);
      }

      getUserdata(event){
        this.userService.getUsers(event).then( users => {
                this.users = users;
      },
          (error)=>{
            return false;
          }
      );
      }

user.service.ts file

 getUsers(page:Number):Promise<User[]>{
     let currentUser = JSON.parse(localStorage.getItem('currentUser'));
    let headers = new Headers({ 'Authorization': `Bearer ${currentUser.token}` });

    let options = new RequestOptions({ headers: headers });

    return this.http.get(`${environment.apiEndPoint}/api/users/${page}`, options)
     .toPromise()
     .then(res=>res.json())
     //.catch(this.errorservice.handleError);
     .catch((error) => {
        //return Promise.reject(error);
       return  this.router.navigate(['/login']);
      })
}

when I send param then show error how can I solve it.

error TS2554: Expected 1 arguments, but got 0.

1
Show your getUsers method from your service - David
Please see above show service.ts file - Md.Jewel Mia

1 Answers

1
votes

The getUsers method returns a Promise, so in your then call back your cannot pass a second argument for error handling.

getUserdata(event){
      this.userService.getUsers(event).then( users => {
              this.users = users;
    })
}

If you want to handle error there, throw an error in your service's catch call back and catch it in getUserData

getUserdata(event){
      this.userService.getUsers(event).then( users => {
              this.users = users;
    }).catch(err=>console.log(err));
   }