I’m having a hard time trying to implement the ngCordova In App Browser, as I followed the instructions to implement ngCordova
in my project and also, I managed to add $cordovaInAppBrowser
in my project with no problem at all. The browser is opening and is loading the webpage like it should.
The hard time comes when I try to catch events from that browser in the application controller, none of the four events seems to be catched by the $on
statement.
Here’s my code:
www/js/app.js
angular.module('starter', ['ionic', 'starter.controllers',
'starter.services', 'ngCordova'])
// ...
.config(function($cordovaInAppBrowserProvider) {
var options = {
location: 'no',
clearcache: 'no',
toolbar: 'no'
};
$cordovaInAppBrowserProvider.setDefaultOptions(options);
});
www/templates/tab-dash.html
<ion-view view-title="Dashboard">
<ion-content class="padding">
<button type="button" name="button" ng-click="openLink()">Open</button>
</ion-content>
</ion-view>
www/js/controllers.js
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope, $rootScope, $cordovaInAppBrowser) {
$scope.openLink = function() {
$cordovaInAppBrowser.open('http://www.google.co.cr', '_blank');
};
$rootScope.$on('$cordovaInAppBrowser:loadstart', function(e, event){
console.log('start');
});
$rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event){
console.log('stop');
});
$rootScope.$on('$cordovaInAppBrowser:loaderror', function(e, event){
console.log('error');
});
$rootScope.$on('$cordovaInAppBrowser:exit', function(e, event){
console.log('exit');
});
});
Even if I define the listener for every event, it doesn’t seem to work. By the way, I’m using Ionic 2.1.8 with Angular 1.
Any help is appreciated, thank you!