Thinker corner fire

everything!

Excuse me for my poor English, please ask me and I will try to explain more.

I am learning angular with the sample operation of http://thinkster.io , and I noticed in lesson 4 that it uses the old version of angularfire (I think it is less than 2), and the syntax of the latter has been changed. I tried to make changes to my code for v2 (for example, I added the $ asArray () element to return $ firebase, and $ add and $ remove started to work. But my find method did not, and $ keyAt returns null. Where is my false?

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; } ); 

and postview.js, where the 'find' method is used:

 'use strict'; app.controller('PostViewCtrl', function($scope, $routeParams, Post){ $scope.post = Post.find($routeParams.postId); }); 
+6
source share
2 answers

I have the same problem.

and, indeed, using $ getRecord in post.js:

 find: function (postId) { return posts.$getRecord(postId); 

and using {{post. $ id}} in posts.html

 <a href="#/posts/{{ post.$id }}">comments</a> 

makes the job just perfect. Although, I’m absolutely noob and I don’t understand why THIS REALLY works. Maybe someone can provide some information? Also, I cannot find the $ getRecord documentation. Can't it work with $ keyAt?

+2
source

I ran into the same problem by making a http://thinkster.io tutorial. I use the latest corner lights 0.8.0 and AngularJS v1.2.16. (installed Yoman)

$ child left in angularfire 0.8.0 https://www.firebase.com/blog/2014-07-30-introducing-angularfire-08.html

In the search method, you should use $ getRecord ();

  find: function(postId){ return posts.$getRecord( postId ); }, 

Also, in views / posts.html, I am passing a message. & id, not postId. (Not sure if this is the right approach, although it works)

 <a href="#/posts/{{ post.$id }}">comments</a> 

PostId seems to behave like $ index. If you specify console.log (postId) or {{postId}} in your view, you will notice this.

Doing these issues makes me wonder if a factory is required with this new API. It seems that this can be done in controllers.

I asked people-thinkers to update their textbook. I hope they do this soon enough.

+1
source

Source: https://habr.com/ru/post/973367/


All Articles