0

Every example I have ever seen of an Angular app with Firebase has had a very static path.

Click Add -> Takes you to a New View

Click Save -> Saves Data and Routes you to a list view

Click on Item (from list view) -> Routes you to edit view of that object using $routeparams

I'm trying to write a function that adds a new object to a fb collection AND route's the user to an edit view of that particular object and in one action. AngularFire's add() method takes a callback, if I could get the $id for the object that was just added in that callback I could use $routeparams to perform the desired action.

Is this even possible?

*Update: I'm using the AngularFire method .add() which turns out was modified to return the new data reference. How is this data actually access though?

e.g. $scope.object.add(localObject);

1
  • You can do var ref = $scope.object.add(localObject) and extract the name via ref.name(). Commented Sep 19, 2013 at 22:02

1 Answer 1

2

if you use push(), name() will give you the id generated by FB.

var ref = new Firebase('https://<yourfb>.firebaseio.com/somepath');
var name = ref.push($scope.currentObject).name();
$location.path('/somepath/' + name);
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah I mean I see that in the API (firebase.com/docs/javascript/datasnapshot/name.html) and that makes sense, but I'm using the AngularFire method .add() (angularfire.com/source.html), which returns the reference after the method runs since this update (github.com/firebase/angularFire/pull/26#issuecomment-19065964). At this point I don't see a way to access the returned data reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.