0

I want to return a boolean promise from this function, any help please?

 getSectionsList() {
let sections: string[] = [];
var ref = this.db.database.ref(`instructors/jDlPCWMMJ8YmD9tMO3shTshM5sx1/sections`);
return ref.once('value').then(function (snap) {
  var array = snap.val();
  for (var i in array) {
    var value = array[i];
    sections.push(value.section)
    //console.log(value.section)
  }
  if (sections.includes('SPRING_2018_CMPS333_L01'))
    return (true)
  else
    return (false)

}).catch(function (err) {
  console.log(err)
})

}

1 Answers1

0

Try injecting the AngularJS $q service...

if (sections.includes('SPRING_2018_CMPS333_L01'))
  return $q.resolve(true);
else
  return $q.resolve(false);

you can also $q.reject(false)

riegersn
  • 2,819
  • 3
  • 17
  • 19