Javascript 使用推(数据)Angularfire2时的手控错误

Javascript 使用推(数据)Angularfire2时的手控错误,javascript,angular,typescript,firebase,angularfire2,Javascript,Angular,Typescript,Firebase,Angularfire2,使用angularFire2推送数据时如何处理错误 我使用了以下方法: todoLists: AngularFireList<TodoList>; addList(data): ThenableReference { const item: Item = { name: data.task, state: false, description: 'No description' }; const todoList: To

使用angularFire2推送数据时如何处理错误

我使用了以下方法:

todoLists: AngularFireList<TodoList>;

addList(data): ThenableReference {

    const item: Item = {
      name: data.task,
      state: false,
      description: 'No description'
    };
    const todoList: TodoList = {
      id: '',
      name: data.name,
      items: [item]
    };
    this.todoLists.push(todoList).then(_ => this.presentToast('List succesfuly added'))
                               .catch(err => _ => this.presentToast('Something wrong happened'));
  }
topolists:AngularFireList;
addList(数据):表格引用{
常量项:项={
名称:data.task,
国家:错,
描述:'无描述'
};
todoList常数:todoList={
id:“”,
name:data.name,
项目:[项目]
};
this.todoLists.push(todoList).then(=>this.presentToast('List successfully added'))
.catch(err=>\u=>this.presentToast('发生了错误');
}
这里的问题是,
AngularFire
的push方法返回一个
thenableference
,因此catch方法在该接口中不存在

以下是来自编辑器(vscode)的消息

promiseLike类型上不存在属性捕获 必须有另一种方法来处理错误


我也遇到了同样的问题,我发现我可以用push()方法创建thenable引用,然后使用set,它会在.catch上返回一个错误

看更多

topolists:AngularFireList;
addList(数据):void{
常量项:项={
名称:data.task,
国家:错,
描述:'无描述'
};
todoList常数:todoList={
id:“”,
name:data.name,
项目:[项目]
};
//.push()还创建一个新的唯一键,可以使用ref.key访问该键
let ref:Reference=this.todoLists.push();
参考集合(todoList)
.然后(()=>this.presentToast('List successfully added'))
.catch(err=>this.presentToast('发生了错误:'+err));
}
相关问题:
todoLists: AngularFireList<TodoList>;

addList(data): void {
  const item: Item = {
    name: data.task,
    state: false,
    description: 'No description'
  };
  const todoList: TodoList = {
    id: '',
    name: data.name,
    items: [item]
  };

  // .push() also creates a new unique key, which can be accessed with ref.key
  let ref: Reference = this.todoLists.push(); 
  ref.set(todoList)
    .then( () => this.presentToast('List succesfuly added'))
    .catch(err => this.presentToast('Something wrong happened: ' + err));
}