Reputation: 87
I am trying to return an array from a service using Promise.Then. The function is my service is follow:
userList: Users[] = [];
getUsers = {
userList: (): Promise<Users[]> => {
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append('Authorization', 'Bearer ' + this.authenticationService.token);
return this.http.get(this.authenticationService.url + '/tournament/getGames', {
headers: headers
}).map((response: Response) => {
var status = response.json().status;
console.log(response.json().status);
if (status) {
this.userList = response.json().users;
console.info(response.json().users);
return this.userList;
}
else {
return null;
}
}).toPromise();
}
}
then I am using this in administrator.component.ts to get the Users list:
usersList: Users[] = [];
inside ngOnInit:
this.getData().then(() => this.isDataAvailable = true);
getData function:
getData(): Promise<Users[]> {
return this.UserService.getUsers().then(users => {
this.usersList= users;
console.log(this.usersList);
});
}
and the code is returning this error message:
cannot invoke an expression whose type lacks a call signature
Any help is much appreciated as I use a similar logic in a different component.
Upvotes: 1
Views: 9853
Reputation: 40544
In your service getUsers
is not a function. getUsers.userList
is the function. So you should call it with this.UserService.getUsers.userList()
.
Upvotes: 2