最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS: Function call on ngSwipeLeft - Stack Overflow

programmeradmin1浏览0评论

Title pretty much explains it all. Inputting ngSwipeLeft="someFunction()" does not seem to work as I hoped it would. Maybe I am doing it wrong, but what are your ideas? Here is the documentation for ngSwipeLeft.

Example

Thanks, Ben

Title pretty much explains it all. Inputting ngSwipeLeft="someFunction()" does not seem to work as I hoped it would. Maybe I am doing it wrong, but what are your ideas? Here is the documentation for ngSwipeLeft.

Example

Thanks, Ben

Share Improve this question edited Apr 24, 2014 at 10:40 benjipelletier asked Apr 24, 2014 at 9:15 benjipelletierbenjipelletier 6735 gold badges11 silver badges30 bronze badges 2
  • We can't tell if you're doing it wrong unless you provide more details ;) For example, are you including the ng-touch module in your application? – Sunil D. Commented Apr 24, 2014 at 9:33
  • @SunilD. Yes, sorry about that. I have updated the question with an example. Thanks, and yes I am including the ng-touch module. – benjipelletier Commented Apr 24, 2014 at 10:40
Add a ment  | 

2 Answers 2

Reset to default 3

I think what you need to do is create a controller for that javascript, and then work off of its scope.

<div ng-show="!showActions" data-ng-swipe-left="someFunction()">
Some list content, like an email in the inbox
</div>
<div ng-show="showActions" data-ng-swipe-right="someFunction()">">
<button ng-click="reply()">Reply</button>
<button ng-click="delete()">Delete</button>
</div>

And the JS

$scope.showActions = false;

$scope.someFunction = function () {
   $scope.showActions = !$scope.showActions;
};

That is how I do it in my applications. I hope it helps.

Here is the Plunk.

The plunk works but it is a little off. It sometimes highlights instead of switching over. It works best when swiping to the right side.

    <div ng-controller="MyCtrl">
        <div>
            <div>
                <pre> Left swipes: {{model.left}}</pre>
            </div>
            <div>
                <pre>Right swipes: {{model.right}}</pre>
            </div>
            <div>
                <pre>Touch clicks: {{model.click}} </pre>
            </div>
        </div>
        <div class="swipy"
            ng-swipe-left="swipeLeft()"
            ng-swipe-right="swipeRight()"
            ng-click="touchClick()">
            Swipe me !
        </div>
    </div>

<style type="text/css">
    div {
        font-size: 0.9em;
    }

    div.swipy {
        text-align: center;
        padding: 15px;
        margin: 5px;
        border-radius: 2px;
        border: 3px groove gray;
        background-color: light-gray;
    }

</style> 
<script type="text/javascript"> 
    app.controller('MyCtrl', function ($scope) {
        $scope.model = {
            left:  0,
            right: 0,
            click: 0
        };
        $scope.swipeLeft = function () {
            $scope.model.left += 1;
        };
        $scope.swipeRight = function () {
            $scope.model.right += 1;
        };
        $scope.touchClick = function () {
            $scope.model.click += 1;
        };
    });

</script>
发布评论

评论列表(0)

  1. 暂无评论