Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

On-hold works but ionicGesture.on hold does not

$
0
0

@Joekomputer wrote:

I'm trying to create a directive that reveals a popup bubble when you tap and hold on the element. When I use the on-hold directive everything seems to work, but when I use the ionicGesture service I am unable to attach focus to revealed element. Here is my code that works:

app.directive("copyContent", function ($rootScope, $compile, $document, $timeout) {
    return {
        link: function ($scope, $element, $attr) {
            var popup = "<div class='copy-popup' ng-show='copying'><input type='button' value='Copy'  ng-click='copyItem()' ng-blur='removePopup()' class='button button-dark'></div>";
            var el = $compile( popup )( $scope );
            $element.append( el );
            $scope.$watch('copying', function(newValue, oldValue) {
                $timeout(function () {
                    if (newValue){
                        $element.addClass('copy-select');
                        el.find('input').focus();
                    }
                });
            });
            $scope.removePopup = function(){
                $scope.copying = false;
                $element.removeClass('copy-select');
            };
            $scope.copyItem = function () {
                var copyString = $attr.copyContent;
                console.log(copyString);
                if(cordova.plugins){
                    cordova.plugins.clipboard.copy(copyString);
                }
                $scope.removePopup();
            };
        }
    };
});

and the html:

<div ng-repeat="comment in comments track by $index" class="message-wrapper">
<div class="chat-bubble right"  copy-content="{{comment}}" on-hold="copying = true"></div>
</div>

The unexpected behavior occurs when I try removing the on-hold directive from the html and instead try using the ionicGesture service within the copy-content directive, like this:

app.directive("copyContent", function ($rootScope, $compile, $document, $timeout, $ionicGesture) {
    return {
        link: function ($scope, $element, $attr) {
            var popup = "<div class='copy-popup' ng-show='copying'><input type='button' value='Copy'  ng-click='copyItem()' ng-blur='removePopup()' class='button button-dark'></div>";
            var el = $compile( popup )( $scope );
            $element.append( el );
            $scope.removePopup = function(){
                console.log('blur');
                $scope.copying = false;
                $element.removeClass('copy-select');
            };
            $scope.copyItem = function () {
                var copyString = $attr.copyContent;
                if(cordova.plugins){
                    cordova.plugins.clipboard.copy(copyString);
                }
               $scope.removePopup();
            };
            $ionicGesture.on("hold", function(){
                $scope.copying = true;
                $timeout(function () {
                    console.log('focus');
                    $element.addClass('copy-select');
                    el.find('input').focus();
                });
            }, $element);
        }
    };
});

and the html:

<div ng-repeat="comment in comments track by $index" class="message-wrapper">
<div class="chat-bubble right"  copy-content="{{comment}}"></div>
</div>

The popup seems to show correctly, but the removePopup function on ng-blur is not fired when clicking outside of the input type=button. Why would using the ionicGesture service cause ng-blur to not be fired correctly, and using the on-hold directive work?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>