1

When I change a selection from combobox, variable "steps" will change and that makes the html change like the following.

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

but when "steps" variable changes by event trigger, I get error message. Error: ViewDestroyedError: Attempt to use a destroyed view: detectChanges

I tried detach and detectchanges but still I get this message. How can I redraw the html?

user3289230
  • 431
  • 2
  • 6
  • 19
  • This probably isn't a problem with the code you've shown. Have you taken a look through [this question](https://stackoverflow.com/questions/37849453/attempt-to-use-a-destroyed-view-detectchanges)? – Vlad274 Sep 11 '18 at 13:55

1 Answers1

0

I am not sure because you show only a part of your code, but it looks like the component is being destroyed but you have not unsubscribed from the observable.

Try to implement OnDestroy in your component and add a function

ngOnDestroy(){
//unsubscribe from your observable for instance if you subscription is called "subs"
this.subs.unsubscribe()
} 
hjbello
  • 643
  • 4
  • 18
  • 1
    @user3289230, could you mark the answer as accepted if you found it useful ? It would be very much appreciated ;) . – hjbello Sep 15 '18 at 00:45