Database provider and it's promises


I’m using this as reference: Ionic 2 - this keyword is undefined when promise is returned from data service

this.database.getTeams().then((response) => {

}, (err){


But if I try to use this it gives me the following error:

property then does not exist on void

This is because I have a method that has a promise in it, and it won’t return anything because it needs to wait for the promise. How is this fixable?

getTeams(){"teams").then((val) => {
  return val;    
}, (err) => {
  return err;


Thanks in advance.

Either do this

getTeams() {


getTeams() {
	return new Promise((resolve, reject) => {"teams").then(
			val => {
			err => {

Because when you call this.database.getTeams().then, you’re expecting a promise from getTeams() and currently you’re only returning the value, buuut you have also placed your returns inside of the callback, meaning they would never make the getTeams() return, just the callback.

If you do either of the above, then your first bit of code should work just fine :slight_smile:

1 Like

That first option is much better. There’s no point in needlessly multiplying entities.