AngularFire 0.9 使用 UI 路由器解析 [英] AngularFire 0.9 resolve with UI router

查看:22
本文介绍了AngularFire 0.9 使用 UI 路由器解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照教程这里 但不知何故犯了这个错误

 未知提供者:currentAuthProvider <- currentAuth

我将 currentAuth 添加到我的所有控制器中,可能有什么问题?

 Firebase 2.0.4AngularFire 0.9.0

这是路由文件:

 .config(function($stateProvider, $urlRouterProvider, $locationProvider) {$urlRouterProvider.otherwise('/');$stateProvider.state('家', {网址:'/',templateUrl: 'views/home.html',控制器:homeCtrl",解决: {currentAuth":[用户工厂",功能(用户工厂){返回 userFactory.$waitForAuth();}]}})

我只有两个模块:

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

这是控制器之一:

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

解决方案

检查您的 HTML 部分视图并删除 ng-controller 声明.

NgRoute 为您实例化控制器并将其绑定到视图中定义的 DOM,因此无需在视图的部分 HTML 中使用 ng-controller 指定控制器.

这有效:

<!-- 在它自己的 HTML 文件中,比如 views/signupCtrl.html --><div><!-- 看,不需要 ng-controller="signupCtrl"... -->...注册表单等...

如果你在那里留下一个 ng-controller 定义(我怀疑这就是你所做的)会发生什么是 angular 会尝试两次实例化控制器:

  • 一旦在加载 DOM 时遇到它,此时 currentAuth 将不会被定义,因此如果它被列为控制器中的依赖项.
  • 一旦解决完成.

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) {

解决方案

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.

这篇关于AngularFire 0.9 使用 UI 路由器解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆