2

We interop our angularJS web components with a jqxGrid. When the user edits in a cell, we create a custom typeahead editor (written in angular). When the editor is destroyed, I noticed that my $watches array doesn't return back to the previous value.

I am creating a new isolateScope for my directive, which I then compile and then append to the DOM element that JQX passes to me when the editor is needed:

var scope = $rootScope.$new(true); var customEditor = $compile(directive)(scope);

What do I have to do in order to clean up these $watches?

flyer
  • 1,414
  • 12
  • 13

2 Answers2

2

Its likely that the new scope you are creating via

var scope = $rootScope.$new(true);

Is not being destroyed by the jqxGrid once the jqxGrid is done with the editor.

To clean up the watches, you simply need to ensure that a call is made to

scope.$destroy();

The tricky part is figuring out when to execute the destroy call; I believe the jqxGrid should raise events such as beforeEdit and afterEdit which you can subscribe to; the place where the $destroy() call should be made is within an event handler for the afterEdit event.

RMD
  • 2,907
  • 30
  • 47
2

Here is the way to clean up watchers effectively. Should angular $watch be removed when scope destroyed? Hope this helps.