【问题标题】:How can I redraw html after event occurs事件发生后如何重绘html
【发布时间】:2023-04-02 12:39:01
【问题描述】:

当我从组合框中更改选择时,变量“步骤”将发生变化,这会使 html 发生如下变化。

<component-item *ngFor="let step of steps ; let i = index" title={{step.title}} ></component-item>

但是当“steps”变量通过事件触发器发生变化时,我会收到错误消息。 错误:ViewDestroyedError:尝试使用已破坏的视图:detectChanges

我尝试了分离和检测更改,但仍然收到此消息。如何重绘 html?

【问题讨论】:

  • 这可能不是您显示的代码的问题。你看过this question吗?

标签: angular


【解决方案1】:

我不确定,因为您只显示了部分代码,但看起来组件正在被销毁,但您尚未取消订阅 observable。

尝试在你的组件中实现OnDestroy并添加一个函数

ngOnDestroy(){
//unsubscribe from your observable for instance if you subscription is called "subs"
this.subs.unsubscribe()
} 

【讨论】:

  • @user3289230,如果您发现它有用,您能否将答案标记为已接受?将不胜感激;)。
猜你喜欢
  • 2021-08-20
  • 1970-01-01
  • 2023-03-08
  • 2012-10-03
  • 1970-01-01
  • 2013-05-04
  • 2015-10-11
  • 1970-01-01
  • 2011-03-17
相关资源
最近更新 更多