简体   繁体   中英

Cannot read property dataTransfer of undefined in AngularJS Ionic

html:

<div ng-if="showSubHeader" class="topPull" draggable >
            <button class="button-icon" on-swipe-down="changeSlide()"><img src="img/topImg.jpg"></button>
                           </div>

directive:

.directive('draggable', function () {
  return function(scope, element) {
        // this gives us the native JS object
        var el = element[0];
        console.log(el)
        el.draggable = true;

        el.addEventListener(
            'dragstart',
            function(e) {
                e.originalEvent.dataTransfer.effectAllowed = 'move';
               // e.dataTransfer.setData('Text', this.id);
                this.classList.add('drag');
                return false;
            },
            false
        );

        el.addEventListener(
            'dragend',
            function(e) {
                this.classList.remove('drag');
                return false;
            },
            false
        );
    }
})

Error:

Uncaught TypeError: Cannot read property 'dataTransfer' of undefined(anonymous function) @ controllers.js:12
app.js:19 Uncaught TypeError: Cannot set property 'effectAllowed' of undefined

How do I fix this error?

I followed this post http://blog.parkji.co.uk/2013/08/11/native-drag-and-drop-in-angularjs.html and need only the draggable directive to work.

Just change the

 e.originalEvent.dataTransfer.effectAllowed = 'move';

with

e.dataTransfer.effectAllowed = 'move';

Demo JSfiddle: http://jsfiddle.net/xvh9L6do/2/

According to : http://blog.parkji.co.uk/2013/08/11/native-drag-and-drop-in-angularjs.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM