简体   繁体   English

如何只刷新组件的一部分而不刷新 angular 中的 ngOnInIt()?

[英]How to refresh only a part of a component without refreshing ngOnInIt() in angular?

I need to know whether there is a way to refresh only the delete reply part without refreshing the whole component with ngOnInIt()我需要知道是否有办法只刷新删除回复部分而不用 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();
    }
   });
  }
 }

You shouldn't call ngOnInit() from another function's scope, it is part of @angular/core您不应该从另一个函数的 scope 调用ngOnInit()它是@angular/core的一部分

See also: https://stackoverflow.com/a/44943103/9766768另请参阅: https://stackoverflow.com/a/44943103/9766768

You will need to provide some context (eg 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.您将需要提供一些上下文(例如您的模板代码),看看在这种情况下哪个ChangeDetectorRef实现是好的做法,但其他评论已经为您指明了正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在单击事件时刷新页面视图的一部分而不刷新整个页面? - How to refresh a part of the page view without refreshing the entire page in angular on a click event? Angular:如何刷新 ngOnInit 方法 - Angular: How to kinda refresh the ngOnInit method Angular ngOnInit - 需要刷新 - Angular ngOnInit - Refresh Needed 如何在不刷新整个页面的情况下从视图中刷新数据? 有角度的 - How to refresh data from view without refreshing the whole page? angular 如何在 Angular 中仅重新加载或刷新子组件 8 - How to reload or refresh only child component in Angular 8 如何不使用ngOnInit()在Angular中显示数据? - How to display data in Angular without ngOnInit()? 如何在不刷新整个页面的情况下更新组件 - Angular - How to Update a Component without refreshing full page - Angular 为什么asyn ngOnInit()中写的代码只有刷新组件后才生效,登录后才生效? - Why the code written in asyn ngOnInit() takes effect only after refreshing the component but not right after the login? Angular:如何只渲染部分组件而不渲染整个组件? - Angular: How to render only part of the component and not the entire component? Angular 4组件@Input ngOnInit未调用 - Angular 4 Component @Input ngOnInit not called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM