在thinkster上的Angularfire

Ром*_*ьев 6 javascript angularjs firebase angularfire

大家!

请原谅我的英语不好,请问我,我会尝试解释更多.

我正在学习http://thinkster.io上的示例工作角度,我在第4课中注意到它使用旧版本的angularfire(我想小于2),并且后者的语法被改变了.我试图在我的v2代码中进行更改(例如我添加了$ asArray()元素来返回$ firebase,$ add和$ remove开始工作.但是我的方法'find'没有,并且$ keyAt返回我的假在哪里?

post.js:

'use strict';

app.factory('Post', 
    function ($firebase, FIREBASE_URL) {
        var ref = new Firebase('https://torid-fire-6813.firebaseio.com/posts');

        var posts = $firebase(ref).$asArray();

        var Post = {
            all: posts,
            create: function (post) {
                return posts.$add(post);
            },
            find: function (postId) {
                return posts.$keyAt(postId);
            },
            delete: function (postId) {
                return posts.$remove(postId);
            }
        };

        return Post;
    }
);
Run Code Online (Sandbox Code Playgroud)

和postview.js,其中使用方法'find':

'use strict';

app.controller('PostViewCtrl', function($scope, $routeParams, Post){
    $scope.post = Post.find($routeParams.postId);
});
Run Code Online (Sandbox Code Playgroud)

小智 1

我在做http://thinkster.io教程时遇到了同样的问题。我正在使用最新的 angularfire 0.8.0 和 AngularJS v1.2.16。(由 Yeoman 安装)

$child 在 angularfire 0.8.0 中消失了https://www.firebase.com/blog/2014-07-30-introducing-angularfire-08.html

在您的 find 方法中,您应该使用 $getRecord();

    find: function(postId){
        return posts.$getRecord( postId );
    },
Run Code Online (Sandbox Code Playgroud)

另外,在views/posts.html 中,我传递的是post.&id,而不是postId。(虽然不确定这是正确的方法,但它有效)

<a href="#/posts/{{ post.$id }}">comments</a>
Run Code Online (Sandbox Code Playgroud)

postId 的行为似乎与 $index 类似。如果您在视图中使用 console.log(postId) 或 {{postId}} ,您会注意到这一点。

遇到这些问题让我想知道这个新 API 是否需要工厂。看来这可以在控制器中完成。

我已经要求思想家更新他们的教程。我希望他们很快就能做到。