“未定义不是函数"使用 angularFire 时出错 [英] "undefined is not a function" error using angularFire

查看:22
本文介绍了“未定义不是函数"使用 angularFire 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示来自 firebase 的数据,我有以下代码.我已经为我的应用声明了 Firebase 依赖项.

i am trying to display data from firebase and i have below code. I already declared firebase dependency for my app.

.controller('AdvMainCtrl', ['$scope', 'dataLoad', 

    function($scope, dataLoad, $route, $routeParams, $location, $resource, angularFire) {
        var categoryPromise = dataLoad.loadCategories($scope, 'categories'),
        tmPromise = dataLoad.loadTransportationMode($scope, 'tModes'),
        tourPromise = dataLoad.loadAdventures($scope, 'tours');
        categoryPromise.then(function() {
            console.log('data loaded');
        });

        $scope.$watch('category', function() {
            if (typeof $scope.category === 'undefined') return;
            console.log('category changed');
            console.log($scope.category.name);
        });
        $scope.$watch('tMode', function() {
            if (typeof $scope.tMode === 'undefined') return;
            console.log('tm changed');
            //console.log($scope.transportationMode.name);
        });
    var ref = new Firebase("https://wpladv.firebaseio.com/adventure");
    $scope.tours = [];
    angularFire(ref, $scope, "tours");
    }
])

在控制台中,我看到 angularFire(ref, $scope, "tours"); 语句中发生的错误.我不知道如何解决这个问题.

in the console i see the error occurring at angularFire(ref, $scope, "tours"); statement. I am not sure how to fix this.

我的控制器中的整个代码是

the entire code in my controller is

.controller('AdvMainCtrl', ['$scope', 'dataLoad',
        function($scope, dataLoad, $route, $routeParams, $location, $resource, angularFire) {
            var categoryPromise = dataLoad.loadCategories($scope, 'categories'),
            tmPromise = dataLoad.loadTransportationMode($scope, 'tModes'),
            tourPromise = dataLoad.loadAdventures($scope, 'tours');
            categoryPromise.then(function() {
                console.log('data loaded');
            });

            $scope.$watch('category', function() {
                if (typeof $scope.category === 'undefined') return;
                console.log('category changed');
                console.log($scope.category.name);
            });
            $scope.$watch('tMode', function() {
                if (typeof $scope.tMode === 'undefined') return;
                console.log('tm changed');
                //console.log($scope.transportationMode.name);
            });
        var ref = new Firebase("https://wpladv.firebaseio.com/adventure");
        $scope.tours = [];
        angularFire(ref, $scope, "tours");
        }
    ])

错误显示在var categoryPromise = dataLoad.loadCategories($scope, 'categories'),"语句

the error is showing at "var categoryPromise = dataLoad.loadCategories($scope, 'categories')," statement

我的 api js 文件中有以下代码.

i have the following code in my api js file.

angular.module('localAdventuresApp')
    .factory('dataLoad', ['angularFire',
        function(angularFire) {
            var dbUrl = 'https://wpladv.firebaseio.com/';

            return {
                loadCategories: function(scope, items) {
                    var cat = '/category';
                    return angularFire(dbUrl + cat, scope, items, []);
                },
                loadTransportationMode: function(scope, items) {
                    var cat = '/transportMode';
                    return angularFire(dbUrl + cat, scope, items, []);
                },
                loadAdventures: function(scope, items) {
                    var cat = '/adventures';
                    return angularFire(dbUrl + cat, scope, items, {});
                }
            }
        }
    ])

错误显示在return angularFire(dbUrl + cat, scope, items, []);"中声明在这里.我在控制台中看到的错误是错误:请提供 Firebase 引用而不是 URL,例如:new Firebase(url)".

the error is being displayed in the "return angularFire(dbUrl + cat, scope, items, []);" statement here. The error which i am seeing in my console is "Error: Please provide a Firebase reference instead of a URL, eg: new Firebase(url)".

推荐答案

你需要将依赖注入你的控制器

you need to inject the dependencies to your controller

.controller('AdvMainCtrl', ['$scope', 'dataLoad', '$route', '$routeParams', '$location', '$resource', 'angularFire',
    function($scope, dataLoad, $route, $routeParams, $location, $resource, angularFire) {
        // your code here
    }
])

这篇关于“未定义不是函数"使用 angularFire 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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