AngularFire - 未定义Firebase

时间:2015-03-05 20:24:28

标签: angularjs firebase angularfire

尝试将AngularFire用于简单的Angular轮询测试应用程序以存储基本对象。我已经尝试注入$ firebase(记录一个错误,告诉我这个被弃用,而不是$ firebaseObject和$ fireBaseArray)。注入这些结果中的任何一个都会导致同一问题不变。

我一直在搜索,但我发现的大多数帖子都提到了bower.json语法错误或JShint特有的内容。它对我来说似乎不属于这些。

错误消息

ReferenceError: Firebase is not defined

指向......

new Firebase(...)

这是我的应用代码:

angular.module('angPoll', ['ui.router', 'firebase']).
config(...).
controller('pollsController', function($scope, pollsData) {
    $scope.pollsList = pollsData.getPolls();
}).
service('pollsData', function($firebaseObject){
    console.log($firebaseObject); <-- [verified here that the injection works]
    var fireRef = new Firebase('https://<my-ref-url>.firebaseio-demo.com/');
    var pollsRef, polls;
    pollsRef = $firebaseObject(fireRef.child('polls')).$asArray();

    this.clearPolls = clearPolls;
    this.setInitialPolls = setInitialPolls;
    this.getPolls = getPolls;
    myDataRef.set({});

    function clearPolls() {
        pollsRef.set({});
    }

    function getPolls() {
        pollsRef.on("value", function(snapshot){
            console.log(snapshot.val());
            polls = snapshot.val();
            return polls;
        })
    }

    function setInitialPolls() {
        pollsRef.set({
            one: {
                name: "fantastic poll"
            },
            two: {
                name: "mediocre poll"
            }
        });
    }

    setInitialPolls();
});

我对这个问题的研究已经开始了:

Firebase, AngularFire Error: Module firebase is not available&lt; - 不是我的问题,因为我已经通过console.log()验证了$ firebaseObject正确地注入到服务中

Angularfire 'Firebase' is not defined&lt; - 定义的Firebase似乎不依赖于此,特别是因为这是一个方法调用我正在尝试初始化ref

https://github.com/firebase/angularfire/issues/362&lt; - 由于某种原因,他们关闭了这个GH问题,仅将其归因于bower.json语法错误,我很确定不是我的情况

我也看过有关JShint的这个突破的帖子,但不是在应用程序本身。我的问题是应用程序本身的功能。

我的bower.json以防万一:

{
  "name": "MyPoll",
  "version": "0.0.0",
  "authors": [
    "thedig"
  ],
  "license": "MIT",
  "private": true,
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "angular": "~1.3.14",
    "angular-ui-router": "~0.2.13",
    "angular-local-storage": "~0.1.5",
    "bootstrap": "~3.3.2",
    "restangular": "~1.4.0",
    "angularfire": "~1.0.0"
  }
}

包含在index.htm中的Angularfire:

<head>

  <link rel="stylesheet" type="text/css" href="../bower_components/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="style.css">
  <script type="text/javascript" src="../bower_components/angular/angular.js"></script>
  <script type="text/javascript" src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>
  <script type="text/javascript" src="../bower_components/angular-local-storage/dist/angular-local-storage.js"></script>
  <script type="text/javascript" src="../bower_components/restangular/dist/restangular.js"></script>
  <script type="text/javascript" src="../bower_components/lodash/dist/lodash.js"></script>
  <script type="text/javascript" src="../bower_components/angularfire/dist/angularfire.js"></script>

  <script type="text/javascript" src="MyPoll.js"></script>


</head>

1 个答案:

答案 0 :(得分:1)

意识到我需要 - 包括AngularFire和Firebase。 Firebase现在被视为全局变量。

...
<script type="text/javascript" src="../bower_components/firebase/firebase.js"></script>
<script type="text/javascript" src="../bower_components/angularfire/dist/angularfire.js"></script>
...