$ firebaseArray注入器问题

时间:2016-09-26 17:27:14

标签: angularjs firebase firebase-realtime-database angularfire

我正在使用Angular和Firebase,并在控制器中注入$firebaseArray时遇到问题。这是代码:

myApp.controller("MeetingsController",
    ['$scope','$rootScope','$firebaseArray',
    function($scope,$firebaseArray,$rootScope){

    var ref = firebase.database().ref();
     var auth = firebase.auth();

        auth.onAuthStateChanged(function(user) {
          if (user) {
            var data = firebase.database().ref('users/' + $rootScope.currentUser.$id + '/meetings');
            var meetingsInfo=$firebaseArray(data);

            $scope.addmeeting=function(){
                meetingsInfo.$add({
                    name:$scope.meetingname,
                    date:firebase.ServerValue.TIMESTAMP
                }).then(function(){
                    $scope.meetingname=' ';
                })
            };
          }
        });

}]);

堆栈跟踪附在下面:

Error: [$injector:unpr] http://errors.angularjs.org/1.5.6/$injector/unpr?p0=%24firebaseArrayProvider%20%3C-%20%24firebaseArray%20%3C-%20MeetingsController
O/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:6:412
db/n.$injector<@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:43:84
d@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:40:344
db/U<@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:43:144
d@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:40:344
e@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:41:78
h/<.instantiate@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:41:445
ff/this.$get</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:90:1
A/<.link@file:///E:/Ex_Files_AngularJS_DataDriven/Ex_Files_AngularJS_DataDriven/Exercise%20Files/ch01/01_02/angulardata/js/lib/angular/angular-route.min.js:7:268
bb/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:16:228
ia@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:81:35
n@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:66:176
g@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:58:429
aa/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:58:67
ac/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:62:428
d@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:59:422
l@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:63:447
x@file:///E:/Ex_Files_AngularJS_DataDriven/Ex_Files_AngularJS_DataDriven/Exercise%20Files/ch01/01_02/angulardata/js/lib/angular/angular-route.min.js:6:364
uf/this.$get</m.prototype.$broadcast@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:147:483
m/<@file:///E:/Ex_Files_AngularJS_DataDriven/Ex_Files_AngularJS_DataDriven/Exercise%20Files/ch01/01_02/angulardata/js/lib/angular/angular-route.min.js:11:408
e/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:130:409
uf/this.$get</m.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:145:103
uf/this.$get</m.prototype.$digest@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:142:165
uf/this.$get</m.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:145:399
l@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:97:248
D@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:101:373
fg/</w.onload@https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:102:397
<main class="cf ng-scope" ng-view="">

我正在关注当前版本的Firebase。我做错了吗?

1 个答案:

答案 0 :(得分:1)

订单不正确,请按此更改,

myApp.controller("MeetingsController",'$scope','$rootScope','$firebaseArray',
    function($scope,$rootScope,$firebaseArray){  

}

另外请确保注入&#39; firebase&#39;作为对模块的依赖,

var app = angular.module("sampleApp", ["firebase"]);

DEMO APP