我想从这个函数返回一个布尔承诺,请帮忙吗?
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)
})
}
答案 0 :(得分:0)
尝试注入AngularJS $ q服务......
if (sections.includes('SPRING_2018_CMPS333_L01'))
return $q.resolve(true);
else
return $q.resolve(false);
你也可以$ q.reject(false)