【发布时间】:2017-12-11 15:48:17
【问题描述】:
Angularfire2 的异步操作有问题。我想在我的 Firebase 数据库中创建一个新资源,但首先我想检查是否存在同名的资源并向前端返回一条消息。
问题是我无法将消息返回到subscribe 方法。 VS 抛出这个错误:
Severity Code Description Project File Line Suppression State
Error TS2355 (TS) A function whose declared type is neither 'void' nor 'any' must return a value.
这是我的功能代码:
createInstance(instanceName: string): string {
this.databaseService.getList('/Events/' + instanceName).subscribe(
result => {
var message;
if (result.length === 0)
{
this.databaseService.update('/Events/' + instanceName + '/Configuration', myObject);
message = "Instance created";
}
else
{
message = "Instance already exists";
}
return message;
});
}
【问题讨论】:
标签: firebase angularfire2 angular5