AngularFire 0.9 resolve with UI router

I've followed a tutorial here but somehow getting this mistake

   Unknown provider: currentAuthProvider <- currentAuth

i added currentAuth to all my controllers, what might be wrong?

 Firebase 2.0.4 
 AngularFire 0.9.0

Here's the routes file:

      .config(function($stateProvider, $urlRouterProvider, $locationProvider) {

     $urlRouterProvider.otherwise('/');

     $stateProvider

         .state('home', {
         url: '/',
         templateUrl: 'views/home.html',
         controller: "homeCtrl",
         resolve: {
             "currentAuth": ["userFactory", function(userFactory) {
                 return userFactory.$waitForAuth();
             }]
         }
     })

i have only two modules:

      var warp = angular.module('warp', [
     'firebase',
     'ui.router'
 ])

and this is one of controllers:

     angular.module('warp')
    .controller("signupCtrl", ["$rootScope", '$scope', 'userFactory', '$window', '$firebase', '$location', 'USERS', 'currentAuth',
        function($rootScope, $scope, userFactory, $window, $firebase, $location, USERS, currentAuth) {

Answers:

Answer

Check your HTML partial view and remove the ng-controller declaration.

NgRoute instantiates the controller for you and binds it to the DOM defined in your view, so there is no need to specify the controller with ng-controller in the view's partial HTML.

This works:

<!-- in it's own HTML file, say  views/signupCtrl.html -->
<div>  <!-- Look, no need for ng-controller="signupCtrl"... -->
  ...signup Form etc...
</div>

What happens if you do leave a ng-controller definition in there (which I suspect is what you did) is that angular will try to instantiates the controller twice:

  • Once when it encounters it when loading the DOM, at which point currentAuth won't be defined, so you would get an unknow provider error if it's listed as a dependency in your controller.
  • Once upon resolve completing.
Answer

You need to inject 'currentAuth' object only to the Controller where you handle sign-in. Worked for me when i deleted it from all other Controllers.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.