InAppBrowser / Promise Problem


#1

Hi !

I think my problem is more PhoneGap and Angularjs than Ionic, but i can’t find answer on Google…

My factory call OAuth service to create an url with token. I use promise to prevent delay of response.
The scripts work fine, until i have to call window.open.

If I call openPopupLogin out of promise, it works ( openPopupLogin(“http://www.ionicframework.com”); ), but if i call openPopupLogin in the promise, it dosen’t work ( openPopupLogin(“http://www.google.fr”); )

Someone may have an idea of the problem !?

Best Regards !

Vincent ( French )

app.controller('accountCtlr', ['OAuthFactory', '$scope', '$window', function ( OAuthFactory, $scope ) {

var _loginWindow;

function openPopupLogin( pUrl ) {
    // Always called
    _loginWindow = window.open( pUrl, '_blank', 'location=no,toolbar=no' );
    if( _loginWindow ) {
        // Called when out of promise
        _loginWindow.addEventListener('loadstart', logEvent, false );
    } else {
        // Called when promise
        window.alert("Error InAppBrowser");
    }
}

function logEvent(e) {
    if ( e.url.indexOf( OAUTH_CONFIG.CALLBACK_URI ) === 0 ) {
        _loginWindow.close();
    }
}

$scope.login = function( event ) {
    event.preventDefault();

    openPopupLogin("http://www.ionicframework.com"); //

    OAuthFactory.getLoginUrl().then(
        function( success ) {
            openPopupLogin("http://www.google.fr");
        }, function( failed ) {
            console.log( failed );
        }
    );
};

}]);


#2

Precision, when i try my application in desktop browser, the window.open work fine in promise.
So it’s only in PhoneGap…


#3

Maybe it’s a $digest problem…


#4

You can see the twitter sample I wrote here ionic.twitter.sample