Skip to content

Calling destroy throws exception #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
floydqwz opened this issue Jun 26, 2014 · 10 comments
Closed

Calling destroy throws exception #110

floydqwz opened this issue Jun 26, 2014 · 10 comments

Comments

@floydqwz
Copy link

The following code in the jqyouiDraggable directive throws an exception:

element.on('$destroy', function() {
element.draggable('destroy');
});

The exception thrown:

Error: cannot call methods on draggable prior to initialization; attempted to call method 'destroy'

Removing the block of code above solves the problem for me.

@codef0rmer
Copy link
Owner

@floydqwz: That snippet is required to avoid memory/dom leaks when an element is no longer available. I think I instantiate the draggable only if the data-drag set to true so while destroying the non instantiated draggable throwing that error.

Can we check if the draggable is instantiated for the element and then only destroy it? If yes, would you mind sending a PR?

@floydqwz
Copy link
Author

On my example page I have four elements with data-drag set to true. I get destroy for all of them but the call fails anyway. So I think it's either 1) The wrong method being invoked. Is is 'destroy'? or 2) Is it too late to call destroy at the point where '$destroy' is called?

@codef0rmer
Copy link
Owner

The method is right. Can you share a demo for me look at?

On Thu, Jun 26, 2014 at 5:21 PM, floydqwz [email protected] wrote:

On my example page I have four elements with data-drag set to true. I get
destroy for all of them but the call fails anyway. So I think it's either

  1. The wrong method being invoked. Is is 'destroy'? or 2) Is it too late to
    call destroy at the point where '$destroy' is called?

Reply to this email directly or view it on GitHub
#110 (comment)
.

With RegardsAmit Gharat
http://amitgharat.wordpress.com/

The luckiest person is one whose passion and profession are the same. *
*--------------------------------------------Q: Why is this email five
sentences or less?A: http://five.sentenc.es http://five.sentenc.es

@floydqwz
Copy link
Author

Tried to create one: http://plnkr.co/edit/A7jRstyPg6LjYGMwld0Y?p=preview
But here $destroy is never called so the code works.

@KylePDavis
Copy link

I can confirm this issue w/ AngularJS v1.3.0-beta14 as well.

In AngularJS v1.2.19 when the $destroy event gets called there is a jQuery instance attached to element.

With AngularJS v1.3.0-beta14 when the $destroy event gets called there is not a jQuery instance attached to the element.

@KylePDavis
Copy link

I think I got the plunkr that @floydqwz started working and demonstrating the issue:

In my case I was able work around the issue by including jQuery, jQueryUI, and then AngularJS.
Using jQuery, AngularJS, and then jQueryUI does NOT work as expected (and does throw the error mentioned above).

I suspect that there's a deeper issue that we need to look into so that it can be fixed or at least ensure that it's given the proper attention in the appropriate documentation.

@kfiil
Copy link

kfiil commented Jul 16, 2014

The "solution" mentioned by @KylePDavis worked for my too. Thanks!!

@dgrad
Copy link

dgrad commented Aug 22, 2014

the fix from @KylePDavis worked for me during testing, but in a production build where jquery, jqueryui and angularjs are all concatenated and minified together, it no longer works (even though the order is the same).

@nhatquang238
Copy link

I'm having the same problem as @dgrad since my production build minifies and includes everything. Hence I have to decouple my production build and require jquery, jquery-ui, angular from cnd source to force it to work. Any official fix on this?

@codef0rmer
Copy link
Owner

Duplicate of #117

codef0rmer pushed a commit that referenced this issue Oct 1, 2014
  - Closes #125, #121, #99 - Fix paradox of choice ($ vs jQuery)
  - Closes #122 - Update jQueryUI depedency in demos and tests
  - Closes #130 - Restore display value if set, else use block
  - Closes #128, #36, #30 - Restore zIndex value always
  - Closes #117, #110 - Fix destroying widgets prior to initialization
  - Closes #111 - Allow dropping without ngModel similar to dragging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants