Ref.close() not working from inside a function just on Android

So, I have the following “sign in page”

<script id="templates/sign-in.html" type="text/ng-template">
    <ion-view title="Login" ng-controller="SignInCtrl">
        <ion-content>
            <ion-list type="list-inset">
                    <button class="button button-block button-positive" ng-click="signIn(user)">
                        Sign-In
                     </button/>
            </ion-list>
        </ion-content>
    </ion-view>
</script>

Using the following controller

app.controller('SignInCtrl', function ($scope) {
    $scope.signIn = function (user) {
        ref = window.open('http://www.google.com', '_blank', 'location=no');
	console.log("now closing");
	ref.close();
	console.log("closed");
    };
})

If I test it on browser (ionic serve), once I click on “Log in” a page is open and immediatly closed. But if I test it on android (ionic run android) the inappbrowser window opens and never closes.

If I move the window.open(…) and the ref.close() code outside the signin function it works both on android and on browser (so as soon as I open the page a new page is open and suddenly closed). Baiscally the following code works correctly both on android and browser:

app.controller('SignInCtrl', function ($scope) {
       ref = window.open('http://www.google.com', '_blank', 'location=no');
	console.log("now closing");
	ref.close();
	console.log("closed");
    $scope.signIn = function (user) {
    };
})

I cannot really figure out why the ref.close() is not working from inside the signin function :\ Any idea?

Hi, have you added the Cordova InAppBrowser plugin?