Unknown provider: $ionicViewProvider

Hi:

I hope someone can help.

I’m trying to use $ionicView.beforeLeave as indicated here: Detecting when a user has moved off a view?

This is my app declaration:

angular.module('starter', ['ionic', 'starter.controllers', 'ionic.contrib.ui.tinderCards', 'ngTable', 'angular-storage'])
...

… and this is my controller:

    .controller('PlanCtrl', function ($scope, $stateParams, appDefaults, $state, store, $parse, SocketService, $ionicPopup, $timeout, $ionicModal, $window, $ionicView) {

        $scope.$on('$ionicView.beforeLeave', function(){
            alert("Before Leaving");
        });
...

… but that gets me:

 Error: [$injector:unpr] Unknown provider: $ionicViewProvider <- $ionicView <- PlanCtrl
http://errors.angularjs.org/1.3.8/$injector/unpr?p0=NaNonicViewProvider%20%3C-%20%24ionicView%20%3C-%20PlanCtrl
    at REGEX_STRING_REGEXP (http://localhost:8100/lib/angular/angular.js:63:12)
    at http://localhost:8100/lib/angular/angular.js:3994:19
    at Object.getService [as get] (http://localhost:8100/lib/angular/angular.js:4141:39)
    at http://localhost:8100/lib/angular/angular.js:3999:45
    at getService (http://localhost:8100/lib/angular/angular.js:4141:39)
    at invoke (http://localhost:8100/lib/angular/angular.js:4173:13)
    at Object.instantiate (http://localhost:8100/lib/angular/angular.js:4190:27)
    at http://localhost:8100/lib/angular/angular.js:8449:28
    at d (http://localhost:8100/lib/ionic/js/ionic-angular.min.js:17:1400)
...

I see $ionicViewService is defined in www/lib/ionic/js/ionic-angular.js.

What am I doing wrong?

Thank you,
~Todd

No need to inject $ionicView into your controller, so we can just do

.controller('MainCtrl', function($scope){
  $scope.$on('$ionicView.beforeLeave', function(){
    alert("Before Leaving");
  });

  $scope.$on('$ionicView.afterLeave', function(){
    alert("After Leaving");
  });
});

Thank you, Mike:

Sorry it’s taken so long to respond. I took out the injection of $ionicView and, though I stopped getting the error, I also never see the alerts which should be triggered by the ionicView events. Not sure what else to try, but also not a show-stopper.