Javascript thinkster上的天使之火
各位! 请原谅我英语不好,请问我,我会尽力解释更多 我正在学习angularfire,在第4课中,我注意到它使用了angularfire的旧版本(我猜少于2个),后者的语法已经更改。我尝试对v2的代码进行更改(例如,我添加了$asArray()元素以返回$firebase,并且$add和$remove开始工作。但是我的方法“find”没有,并且$keyAt返回null。我的false在哪里 post.js:Javascript thinkster上的天使之火,javascript,angularjs,firebase,angularfire,Javascript,Angularjs,Firebase,Angularfire,各位! 请原谅我英语不好,请问我,我会尽力解释更多 我正在学习angularfire,在第4课中,我注意到它使用了angularfire的旧版本(我猜少于2个),后者的语法已经更改。我尝试对v2的代码进行更改(例如,我添加了$asArray()元素以返回$firebase,并且$add和$remove开始工作。但是我的方法“find”没有,并且$keyAt返回null。我的false在哪里 post.js: 'use strict'; app.factory('Post', func
'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;
}
);
和postview.js,其中使用了“find”方法:
'use strict';
app.controller('PostViewCtrl', function($scope, $routeParams, Post){
$scope.post = Post.find($routeParams.postId);
});
我在做教程时遇到了同样的问题。我使用的是最新的angularfire 0.8.0和AngularJS v1.2.16。(由Yeoman安装) $child在angularfire 0.8.0中消失 在find方法中,应该使用$getRecord() 另外,在views/posts.html中,我传递的是post&id,而不是postd。(虽然不确定这是正确的方法,但它是有效的)
postId的行为似乎与$index类似。如果您在视图中使用console.log(postId)或{{postId}},您会注意到这一点
遇到这些问题让我想知道工厂是否有必要使用这个新的API。看起来它可以在控制器中完成
我已经请thinkster的人更新他们的教程。我希望他们很快就会更新。我也有同样的问题 实际上,在post.js中使用$getRecord:
find: function (postId) {
return posts.$getRecord(postId);
并在posts.html中使用{post.$id}}
<a href="#/posts/{{ post.$id }}">comments</a>
让它工作得很好。不过,我是个傻瓜,不太明白为什么会这样。也许有人可以提供一些信息?另外,我找不到$getRecord文档。它不能与$keyAt一起工作吗?用$getRecord替换$keyAt,你就可以了。顺便说一句,可能没有必要发布此帖子对象。它直接包装可以在同步数组上调用的方法。我想这一定与版本有很大关系。我不能使用keyAt或getRecord,我在其他地方看到应该使用$child。你能说明你使用的firebase和angularfire的哪个版本吗?我的版本:
“dependencies”:{“angular”:~1.2.21“json3”:“3.3.1”,“es5垫片”:“3.1.0”,“引导”:“3.2.0”,“角度资源”:“1.2.16”,“角度cookies”:“1.2.16”,“角度清理”:“1.2.16”,“角度动画”:“1.2.16”,“角度触摸”:“1.2.16”,“角度路线”:“1.2.16”,“角度火”:“~0.8.0”,“firebase”:“1.0.19”},
更新后。但是$getRecord不起作用,就像$keyAt一样。它返回'null'。
find: function (postId) {
return posts.$getRecord(postId);
<a href="#/posts/{{ post.$id }}">comments</a>