大家!
请原谅我的英语不好,请问我,我会尝试解释更多.
我正在学习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)