[英]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.