升级 AngularFire 会导致脚本停止工作吗? [英] Upgrading AngularFire causes scripts to stop working?

查看:25
本文介绍了升级 AngularFire 会导致脚本停止工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下脚本是使用 angularfire、firebase 和 angular 对 firebase 的简单读取.问题是,当我将 AngularFire 从 0.7.1 升级到 .0.8.0 时,脚本完全停止工作,我不确定我做错了什么?

<部分 ng-app="myapp" ng-controller="MyController"><div ng-repeat="数据中的项目"><h3 ng-cloak>{{item.title}}</h3>

</节><脚本>angular.module("myapp", ["firebase"]).factory("FirebaseService", ["$firebase", function ($firebase) {var furl = "https://helloworldtest.firebaseio.com/";var ref = new Firebase(furl);返回 $firebase(ref);}]).controller('MyController', ["$scope", "FirebaseService", function ($scope, firebaseservice) {$scope.data = firebaseservice}]);

有了这个配置就可以正常工作了:

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

但是这样就行不通了:

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

也许最好不要升级.

解决方案

在你的控制器中:-

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

或者在您的服务中进行:-

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

演示

我从未使用过 Firebase,但似乎这是为改进功能而引入的重大更改,在这里找到

<块引用>

在以前的版本中,Firebase 数据在 AngularFire 绑定初始化时加载.改进后的 API 提供了两种加载不同格式数据的方法.这些方法是 $asObject() 和 $asArray().

根据来自 Kato

的评论更新

这是更改日志,说明了新版本.它说明了许多重大更改的引入,所以我想在 1.0 稳定版本完成之前你可以期待同样的变化.这是官方 API 文档.

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.

解决方案

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.

这篇关于升级 AngularFire 会导致脚本停止工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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