Peter Wilson
Peter Wilson

Reputation: 4319

InAppBrowser Events handling issue

I am working on mobile app using:

I've one view with external url using InAppBrowser plugin and I have a link in this website should redirect to certain view in my app

this issue is $location.url() not redirecting and not working at all, but when I tested the event I found it trigger normally.

here is my full code

angular.module('yogipass').controller('iframe',function ($location) {
 document.addEventListener("deviceready", onDeviceReady, false);

 function onDeviceReady() {
  console.log('here');

  var ref=cordova.InAppBrowser.open('http://192.168.42.218/index.html', '_blank', 'location=no');

  ref.addEventListener('loadstart', function(event) {
   if (event.url.match("mobile/login")) {
    console.log('worked!') // this logged normally
    $location.url('/login');

      ref.close();
   }
  });




}

])

Upvotes: 1

Views: 361

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136184

You have to run digest cycle manually as you are changing location path from asynchronous event which is outside angular context.

Do wrap you code in $timeout function, which will fire up digest cycle. Apparently that will help to update location.

$timeout(function(){
    $location.url('/login');
})

Upvotes: 1

Related Questions