Upgrading AngularFire causes scripts to stop working?

好久不见. 提交于 2019-12-13 05:17:26

问题


The following script is a simple read from firebase using angularfire, firebase, and angular. The issue is that when I upgrade AngularFire from 0.7.1 to .0.8.0 the script completely stops working and I'm not sure what I'm doing wrong?

<body>
<section ng-app="myapp" ng-controller="MyController">
    <div ng-repeat="item in data">
         <h3 ng-cloak>{{item.title}}</h3>
    </div>
</section>
<script>

angular.module("myapp", ["firebase"])


.factory("FirebaseService", ["$firebase", function ($firebase) {
    var furl = "https://helloworldtest.firebaseio.com/";
    var ref = new Firebase(furl);
    return $firebase(ref);
    }])

.controller('MyController', ["$scope", "FirebaseService", function ($scope, firebaseservice) {

    $scope.data = firebaseservice

}]);

Wit this configuraiton it works fine:

<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.6/angular.min.js'></script>
<script src='https://cdn.firebase.com/js/client/1.0.17/firebase.js'></script>
<script src='https://cdn.firebase.com/libs/angularfire/0.7.1/angularfire.min.js'></script>

but with this, it doesn't work:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js"></script>
<script src="https://cdn.firebase.com/js/client/1.0.18/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/0.8.0/angularfire.min.js"></script>

Perhaps it's better not to upgrade.

  • See working JSFiddle: http://jsfiddle.net/chrisguzman/z8Lpj63w/
  • See not working JSFiddle (with angularfire upgrade): http://jsfiddle.net/chrisguzman/z8Lpj63w/

回答1:


In your controller do:-

 $scope.data = firebaseservice.$asArray(); //or .$asObject

Or do it in your service:-

 return $firebase(ref).$asObject(); //or .$asObject

Demo

I have never used Firebase but seems like this is a breaking change introduced to improve the functionality, Found it here

In previous versions, Firebase data loaded when the AngularFire binding initialized. The improved API provides two methods that load data in different formats. Those methods are $asObject() and $asArray().

Update based on comment from Kato

Here is the change log stating the changes in the new version. It states the introduction of many breaking changes, so i guess you can expect the same until 1.0 stable release is done. Here is the official api documentation.



来源:https://stackoverflow.com/questions/25416654/upgrading-angularfire-causes-scripts-to-stop-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!