小编Abh*_*ith的帖子

订阅被调用两次

我正在尝试创建一个表单来提交详细信息,但是当我订阅该服务时,订阅完成了两次。第一个是空数据,第二个是实际数据。

组件.ts

addBook() {
    this.errorMessage = null;
    this.fireService.getBook(this.bookDetails.isbn).subscribe(data => {
      console.log('subscribe called');
      if (null != data) {
        this.dbox.open(DialogBoxComponent, {
          data: { title: 'Error', content: 'Book is already present in Library. Select Edit book to modify the details', button: false }
        });
        this.errorMessage = 'Book is already present in Library. Select Edit book to modify the details';
      } else {
        this.fireService.addBook(this.bookDetails);
        this.dbox.open(DialogBoxComponent, {
          data: { title: 'Success', content: 'Book has been Added to Database', button: false }
        });
        this.router.navigateByUrl('/add-book');
      }
    }); …
Run Code Online (Sandbox Code Playgroud)

javascript firebase typescript angular angular5

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular5 ×1

firebase ×1

javascript ×1

typescript ×1