Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

Drag and drop gives an error with Angular 1.3.* when you have debugInfo disabled.

Open vikasgarghb opened this issue 11 years ago • 12 comments

Hi, I am using ng-sortable with angular 1.3.* and have debugInfo disabled for production. But doing so, gives a JS error Uncaught TypeError: Cannot read property 'indexOf' of undefined. The error is on this line in ng-sortable.js, oldIndex = prevItems.indexOf(prevSource.item(evt.item));. I debugged it and found that the actual issue arise on this line in ng-sortable.js, var scope = angular.element(el).scope();

scope returned here is undefined. According to this, https://docs.angularjs.org/api/ng/function/angular.element scope() method will return undefined when debugInfo is disabled. Enabling the debugInfo in production is not an option for me as this would cause some performance overhead in our application. Here is more information on disabling debugInfo https://docs.angularjs.org/guide/production#disabling-debug-data

vikasgarghb avatar Feb 02 '15 19:02 vikasgarghb

I do not know how to fix it, alas.

RubaXa avatar Feb 06 '15 09:02 RubaXa

Hi,

Maybe you can try either :

  • In .directive('ngSortable', ['$parse', function ($parse) { you could try to add "$scope" dependency and use it later.
  • In the link function, you have a scope parameter

I think the second is better

maitredede avatar Feb 26 '15 06:02 maitredede

Unfortunately this is a serious issue. Running a system with enabled debugInfoEnabled is not a recommendation in production environments.

Can you maybe accept items array as param when initializing ng-sortable?

godza avatar Apr 11 '15 01:04 godza

Anyone looking at this? I'm having the same problem.

andre-gois avatar Jul 17 '15 15:07 andre-gois

Hi, Interested in a fix for this as well. I see andre-gois has committed a fix. Is it good? Thanks

bhecht2 avatar Jul 21 '15 05:07 bhecht2

Sorry, I submitted the previous commit by mistake. But in the meantime I have a quick fix. By moving the getSource function into the link function, and using that scope instead of getting it from the element. I'll do another pull request with the corrected version so you guys can have a look.

The problem was when you have debugInfo disabled you can't get scope from elements (it's not even a good practice, it's just there for debug purposes - Batarang, etc).

andre-gois avatar Jul 21 '15 13:07 andre-gois

@RubaXa Did you have a chance to take a look on PR #514 ?

screamy avatar Aug 31 '15 08:08 screamy

@screamy Yes, I watched it, but not yet ready to accept it. If I wanted to do so, would have done originally.

RubaXa avatar Aug 31 '15 08:08 RubaXa

@screamy Alas, there is no time to deal with this problem. Those who want to use with disbled debugInfo, can take this patch.

RubaXa avatar Aug 31 '15 08:08 RubaXa

Fixed into dev-branch.

RubaXa avatar Sep 04 '15 12:09 RubaXa

Those who want to use with disbled debugInfo, can take this patch.

Because disabling debug data is the first thing you might consider before running any Angular app in production, I think the README should mention in a clearly visible place that this plugin isn't compatible with Angular's production usage considerations.

Running an AngularJS App in Production

akoskm avatar Jun 09 '16 08:06 akoskm

the latest code in dev branch doesn't work w/debugInfoEnabled(false)

DealerCorp avatar Sep 08 '16 20:09 DealerCorp