Reference.child失败:第一个参数是无效路径=“[object Object]”

时间:2018-04-12 15:59:22

标签: angular firebase

角色新品。

我正在尝试删除我的系列数据库的一个季节,当我删除一个系列时,它确实可以,但是当我尝试删除一个季节时它会这样做

错误:

ERROR Error: Reference.child failed: First argument was an invalid path = "[object Object]". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
    at Object.exports.validatePathString (validation.js:282)
    at Reference.child (Reference.js:74)
    at Object.stringCase (remove.js:8)
    at checkOperationCases (utils.js:19)
    at Object.remove (remove.js:7)
    at SeriesDataService.deleteSeason (series-data.service.ts:73)
    at SeasonDetailComponent.delete (season-detail.component.ts:44)
    at Object.eval [as handleEvent] (SeasonDetailComponent.html:28)
    at handleEvent (core.js:13547)
    at callWithDebugContext (core.js:15056)

和我的SeasonDetailComponent.html看起来像这样:

<div *ngIf="season">
<h2>Season {{season.Number}} details</h2>
<div>
     <label>Number:
      <input [(ngModel)]="season.Number" placeholder="Number"/>
    </label><br/>
    <label>Image: 
    <img src="" alt="">
        <input  [(ngModel)]="season.Image" placeholder="Image source">
    </label><br/>
    <label>First_Episode_Air_Date:
      <input [(ngModel)]="season.First_Episode_Air_Date" placeholder="First_Episode_Air_Date"/>
    </label><br/>
    <label>Last_Episode_Air_Date:
      <input [(ngModel)]="season.Last_Episode_Air_Date" placeholder="First_Episode_Air_Date"/>
    </label><br/>
</div>

</div>
<button (click)="goBack()">Go back</button>
<button [routerLink]="['./episodes']">Episodes</button>
<button (click)="delete()">X</button>

季节细节组件:

 delete(): void{
    this._data.deleteSeason(this.serieId, this.season.Number);
    this.goBack();
  }

和我的series-data.service.ts是这样的:

deleteSeason (idSerie: number , Number: number):  void {
    const indexSerie = this.db.list(this.authService.userDetails.uid+"/"+idSerie+"/").valueChanges();;
    const indexSeason = this.db.list(this.authService.userDetails.uid+"/"+idSerie+"/Seasons"+Number).valueChanges();
    //this.db[serieId].Seasons.splice(indexSeason, 1);
    console.log("Removing: "+idSerie+ " season " +Number);
    this.db.list(this.authService.userDetails.uid).remove(indexSeason.toString());
  } 

谢谢!

1 个答案:

答案 0 :(得分:0)

问题已解决!

将series-data.service的deleteSeason更改为:

deleteSeason (id:number,serieId):void {
    console.log("Removing: "+serieId+" season " +id);
    this.db.list(this.authService.userDetails.uid+"/"+serieId+"/Seasons").remove(id.toString());
  }