【问题标题】:How would I add a swipe action in Javascript using Angular Material如何使用 Angular Material 在 Javascript 中添加滑动操作
【发布时间】:2016-05-25 19:28:29
【问题描述】:

我有兴趣使用 ngMaterial 的滑动,因为我收到警告...

您正在使用 ngTouch 模块。 Angular Material 已经支持移动点击、点击和滑动... Angular 材质不支持 ngTouch!

问题是现在这个元素不在指令之下。相反,我目前使用 angular.element 来抓取它,然后使用 ngTouch 发布全局事件...

$rootScope.$broadcast('gesture', gestures);

我知道它可能不是material-way,但我只想手动附加滑动事件。

更新

这看起来很有希望,虽然没有记录...

$mdGesture.register(myElement, 'drag', { minDistance: 20, horziontal: false })

【问题讨论】:

    标签: angularjs angular-material


    【解决方案1】:

    这是我的工作版本

    function TouchService($mdGesture, $rootScope){
        this.setElement = function (selector) {
            var element = angular.element(selector);
            $mdGesture.register(element,'swipe', { minDistance: 20, horziontal: false });
            element.on("$md.swipeleft", function(){
                $rootScope.$broadcast('gesture', {direction: 'left'});
            });
            element.on("$md.swiperight", function(){
                $rootScope.$broadcast('gesture', {direction: 'right'});
            });
            element.on("$md.swipeup", function(){
                $rootScope.$broadcast('gesture', {direction: 'up'});
            });
            element.on("$md.swipedown", function(){
                $rootScope.$broadcast('gesture', {direction: 'down'});
            });
        };
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多