Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use case: user settings / dictionary support / ordered dictionary #32

Closed
bennlich opened this issue May 24, 2013 · 9 comments
Closed

use case: user settings / dictionary support / ordered dictionary #32

bennlich opened this issue May 24, 2013 · 9 comments

Comments

@bennlich
Copy link

It would be very helpful if angularFireCollections were key-accessible.

I'm trying to save some user settings to firebase. I'd like the settings object to look like:

settings: {
  firstName: "",
  lastName: ""
}

or, if necessary:

settings: {
  firstName: { val: "" },
  lastName: { val: "" }
}

To deal with ordering and human-readable titling, I'm planning to use a $scope variable outside of Firebase:

function myCtrl( ... ) {
  $scope.settingsModel = [
    { key: "firstName", title: "First name" },
    { key: "lastName", title: "Last name" }
  ];
  $scope.settingsCollection = angularFireCollection( ... );
}

Then my view can look like:

<div ng-repeat="field in settingsModel">
  <label>{{ field.title }}</label>
  <input ng-model="settingsCollection[field.key].val">
</div>

There doesn't seem to be a way to access elements of an angularFireCollection by key, though, so this won't work. Has anyone else run into a similar use case?

It would also seem natural to be able to do something like:

<div ng-repeat="(key, field) in settingsModel">
  {{ key }} : {{ field }}
</div>
@anantn
Copy link
Contributor

anantn commented Aug 30, 2013

We added getByName and getByNames to angularFireCollection recently that should help with this. Re-open if that doesn't help!

@anantn anantn closed this as completed Aug 30, 2013
@becush
Copy link

becush commented Sep 8, 2013

Can you give an example of how to use this? Using getByName inside the controller returns undefined because the collection hasn't populated yet. Placing it inside a callback doesn't seem to help either.

@johnsoftek
Copy link
Contributor

Not sure how settings fit in to your other requirements. But try this (implicit update):
http://plnkr.co/edit/yVWMmQVXZp3T8e5ZlVNO?p=preview

@johnsoftek
Copy link
Contributor

Here is an explicit update version of the previous plnkr: http://plnkr.co/edit/KztBQDET6XVOdjkxoZgG?p=preview

@vzhen
Copy link

vzhen commented Sep 15, 2013

@bennlich Do you figure out how to use getByName and getByNames?

@becush
Copy link

becush commented Sep 15, 2013

For me, it only returns an integer, which is not an index. Very confused.

On Sun, Sep 15, 2013 at 2:01 PM, vzhen notifications@github.com wrote:

@bennlich https://github.com/bennlich Do you figure out how to use
getByName and getByNames?


Reply to this email directly or view it on GitHubhttps://github.com//issues/32#issuecomment-24476426
.

@johnsoftek
Copy link
Contributor

getByName returns the item in the collection.

@becush
Copy link

becush commented Sep 17, 2013

Well, I know what's it's supposed to do, i'm just saying, the following:

var collection = angularFireCollection(new Firebase(URL));
var item = collection.getByName('-IsiklzTd90LIwWOI81Y');

For ME, item = 8, sometimes item = 7. If i'm doing something wrong,
please let me know, thanks!

On Tue, Sep 17, 2013 at 8:02 AM, johnsoftek notifications@github.comwrote:

getByName returns the item in the collection.


Reply to this email directly or view it on GitHubhttps://github.com//issues/32#issuecomment-24565854
.

@johnsoftek
Copy link
Contributor

Hmm. So what are the objects in your collection? What object corresponds to
the example item Id?

On Tuesday, 17 September 2013, becush wrote:

Well, I know what's it's supposed to do, i'm just saying, the following:

var collection = angularFireCollection(new Firebase(URL));
var item = collection.getByName('-IsiklzTd90LIwWOI81Y');

For ME, item = 8, sometimes item = 7. If i'm doing something wrong,
please let me know, thanks!

On Tue, Sep 17, 2013 at 8:02 AM, johnsoftek <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>>wrote:

getByName returns the item in the collection.


Reply to this email directly or view it on GitHub<
https://github.com/firebase/angularFire/issues/32#issuecomment-24565854>
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/32#issuecomment-24570912
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants