AngularFire 0.9 Enables UI Router Operation

I followed the tutorial here , but somehow got this error

Unknown provider: currentAuthProvider <- currentAuth 

I added currentAuth to all my controllers, what could be wrong?

  Firebase 2.0.4 AngularFire 0.9.0 

Here's the route 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 the controllers:

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

Check the partial appearance of the HTML and remove the ng-controller declaration.

NgRoute configures the controller for you and associates it with the DOM defined in your view, so there is no need to specify the controller with the ng controller in a partial HTML view.

It works:

 <!-- in it 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 the ng controller definition there (I suspect you did) is that angular will try to instantiate the controller twice:

  • When it encounters it when loading the DOM, currentAuth will not be detected at this point, so you will get an unknow provider error message if it is specified as in your controller.
  • Upon completion of the decision .
+3
source

You need to add the currentAuth object only to the controller in which you are handling the input. Worked for me when I removed it from all other controllers.

-1
source

Source: https://habr.com/ru/post/1203784/


All Articles