ionic-team / ionic-v1

The repo for Ionic 1.x. For the latest version of Ionic, please see https://github.com/ionic-team/ionic
Other
193 stars 187 forks source link

$ionicScrollDelegate not working for ionic popups (ion-modal-view) #157

Open jgw96 opened 7 years ago

jgw96 commented 7 years ago

From @ashutosh-akss on March 21, 2016 10:40

I am trying to resize modal view height after adding dynamic content.

I have given delegate-handle to my content

<ion-modal-view>
     <ion-content delegate-handle="create-post">

     </ion-content>
</ion-modal-view>

and then from my controller i am calling

$ionicScrollDelegate.$getByHandle('create-post').resize();

but it gives following error

ionic.bundle.js:21157 Delegate for handle "create-post" could not find a corresponding element with delegate-handle="create-post"! resize() was not called! Possible cause: If you are calling resize() immediately, and your element with delegate-handle="create-post" is a child of your controller, then your element may not be compiled yet. Put a $timeout around your call to resize() and try again.

if i echo my $ionicScrollDelegate i get 3 instances.

this works for normal view.. any suggestions?

Thanks in advance

Cordova CLI: 6.0.0 Ionic CLI Version: 1.7.12 Ionic App Lib Version: 0.6.5 OS: Distributor ID: Ubuntu Description: Ubuntu 14.04.4 LTS Node Version: v5.0.0

Copied from original issue: driftyco/ionic#5897

jgw96 commented 7 years ago

From @leschirmeur on March 23, 2016 9:53

$ionicScrollDelegate.$getByHandle() does not work in modals. To circumvent this, we are using a custom scrollDelegate service instead of the default one from ionic which have have taken from https://github.com/driftyco/ionic/issues/2754. Our service looks as follows:

// $ionicScrollDelegate not working for content in modals
// as described here: https://github.com/driftyco/ionic/issues/2754
// So using an intermediary service until it's fixed.
// Change to return standard and it should use native functionality.
angular
        .module('quiply')
        .service('QyScrollDelegate', QyScrollDelegate);

    /* @ngInject */
    function QyScrollDelegate($ionicScrollDelegate) {
        var custom = {
            $getByHandle: function(name) {
                var instances = $ionicScrollDelegate.$getByHandle(name)._instances;
                return instances.filter(function(element) {
                    return (element['$$delegateHandle'] == name);
                })[0];
            }
        };

        return custom;
    }

Then we are using it by injecting QyScrollDelegate first and then

QyScrollDelegate.$getByHandle('some-handle')

Hope this helps.

jgw96 commented 7 years ago

From @ashutosh-akss on March 23, 2016 10:13

Thanks @leschirmeur , i will check this now

Defcon0 commented 7 years ago

Any progress on that one? At least the fix in https://github.com/driftyco/ionic-v1/issues/157#issuecomment-272572026 works.