0

I need to know whether there is a way to refresh only the delete reply part without refreshing the whole component with ngOnInIt()

 public deleteReply(commentId, replyId) {
    this.isLoadingReplyDelete = true;
    this.discussionService.deleteReply(commentId, replyId).takeWhile(() => this.alive)
      .subscribe(returnObj => {
     if (returnObj.status === 200) {
      this.isLoadingReplyDelete = false;
      this.ngOnInit();
    }
   });
  }
 }
Ganesh
  • 5,808
  • 2
  • 21
  • 41
  • const index = this.listData.data.indexOf(key); this.listData.data.splice(index, 1); and then you can call refreshing get data api method.. – Developer Oct 29 '19 at 05:16
  • If part of a component can b refreshed on its own, it should then be a child component of the current one. – Antediluvian Oct 29 '19 at 05:40
  • Take a look about change detector in angular https://angular.io/api/core/ChangeDetectorRef and take a look also on this article https://blog.angular-university.io/how-does-angular-2-change-detection-really-work/ – Tawfiek Khalaf Oct 29 '19 at 06:20

1 Answers1

0

You shouldn't call ngOnInit() from another function's scope, it is part of @angular/core

See also: https://stackoverflow.com/a/44943103/9766768

You will need to provide some context (e.g. your template code) see you which implementation of ChangeDetectorRef would be good practice in this case, but other comments have pointed you in the right direction.

Friso Hoekstra
  • 845
  • 2
  • 9
  • 24