Angularfire角火基地

时间:2017-11-16 22:15:59

标签: angular typescript firebase angularfire

尝试编辑/更新时,我收到以下错误消息。这个错误是什么意思?

我更改了路径而不是$key我放id,但错误仍然存​​在。任何帮助将不胜感激。

  

" EditBookComponent.html:52错误错误:Reference.child失败:第一个参数是无效路径=" books / [object Object]"。路径必须是非空字符串,并且不能包含"。","#"," $"," [& #34;,或"]"       "       "

// TODO = Perf = Consider combining the recursive validation of keys into NodeFromJSON
    // to save extra walking of large objects.
    if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') {
        var hasDotValue_1 = false,
            hasActualChild_1 = false;
        (0, _obj.forEach)(data, function (key, value) {
            if (key === '.value') {
                hasDotValue_1 = true;
            } else if (key !== '.priority' && key !== '.sv') {
                hasActualChild_1 = true;
                if (!isValidKey(key)) {
                    throw new Error(errorPrefix + ' contains an invalid key (' + key + ') ' + path.toErrorString() + '.  Keys must be non-empty strings ' + 'and can\'t contain ".", "#", "$", "/", "[", or "]"');
                } 

更新

这是代码。 PushUpload和updateBooklet函数。

在service.ts中:

pushUpload(upload: Upload) {
  const storageRef = firebase.storage().ref();
  const uploadTask = storageRef.child(`${this.basePath}/${upload.file.name}`).put(upload.file);

  const sub = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
    (snapshot) =>  {
      // upload in progress
      const snap = snapshot as firebase.storage.UploadTaskSnapshot
      upload.progress = (snap.bytesTransferred / snap.totalBytes) * 100
    },
    (error) => {
      // upload failed
      console.log(error)
    },
    ():any => {
      // upload success
      upload.imageUrl = uploadTask.snapshot.downloadURL
      upload.name = upload.file.name
      // this.saveFileData(upload)
      return upload.file.name
    }
  );

  return uploadTask.then(snap => this.saveFileData(upload).key)
}


// Writes the file details to the realtime db
private saveFileData(upload: Upload) {
  return this.db.list(`${this.basePath}/`).push(upload);
}


updateBooklet(book, id){
     return this.db.object('books/'+ id).update(book);
   }


in the routes I put this:

const appRoutes : Routes = [
  {path:'', component:HomeComponent},
  {path:'book-list', component:BookListComponent},
  {path:'book-details/:id', component:BookDetailsComponent},
  {path:'add-book', component:AddBookComponent},
  {path:'edit-book/:id', component:EditBookComponent}

0 个答案:

没有答案