# Unknown provider: $ionicViewProvider

**URL:** <https://forum.ionicframework.com/t/unknown-provider-ionicviewprovider/18044>\
**Category:** ionic-v1\
**Created:** [February 22, 2015, 8:05pm UTC](https://forum.ionicframework.com/t/unknown-provider-ionicviewprovider/18044 "2015-02-22T20:05:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![todd\_rimes](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/todd_rimes/32/72420_2.png) [@todd\_rimes](https://forum.ionicframework.com/u/todd_rimes)\
**Post date:** [February 22, 2015, 8:05pm UTC](https://forum.ionicframework.com/t/unknown-provider-ionicviewprovider/18044/1 "2015-02-22T20:05:01Z")

</div>

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?](http://forum.ionicframework.com/t/detecting-when-a-user-has-moved-off-a-view/14789/4?u=todd_rimes)

This is my app declaration:

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

```

… and this is my controller:

```auto
    .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:

```auto
 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

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [February 23, 2015, 5:45pm UTC](https://forum.ionicframework.com/t/unknown-provider-ionicviewprovider/18044/2 "2015-02-23T17:45:09Z")

</div>

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

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

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

```

---

<div class="post-metadata">

**Author:** ![todd\_rimes](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/todd_rimes/32/72420_2.png) [@todd\_rimes](https://forum.ionicframework.com/u/todd_rimes)\
**Post date:** [March 10, 2015, 10:56pm UTC](https://forum.ionicframework.com/t/unknown-provider-ionicviewprovider/18044/3 "2015-03-10T22:56:21Z")

</div>

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.
