Drag and drop gives an error with Angular 1.3.* when you have debugInfo disabled.
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
I do not know how to fix it, alas.
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
linkfunction, you have ascopeparameter
I think the second is better
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?
Anyone looking at this? I'm having the same problem.
Hi, Interested in a fix for this as well. I see andre-gois has committed a fix. Is it good? Thanks
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).
@RubaXa Did you have a chance to take a look on PR #514 ?
@screamy Yes, I watched it, but not yet ready to accept it. If I wanted to do so, would have done originally.
@screamy Alas, there is no time to deal with this problem. Those who want to use with disbled debugInfo, can take this patch.
Fixed into dev-branch.
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.
the latest code in dev branch doesn't work w/debugInfoEnabled(false)