Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

feat(ngModel): bind to single property instead of entire object #107

Merged
merged 4 commits into from
Jul 29, 2014

Conversation

dimirc
Copy link
Contributor

@dimirc dimirc commented Jul 14, 2014

In cases when we don't want the ngModel to be bind to the whole object but just to a property, we could specify it at the repeat attribute.

Something like this:
person.email as person in people

I'm doing some refactoring at this PR but the important part of the code is at the link function uf uiSelect directive, where a parser and formatter is added (to have 2 way binding)

PD: For static data seams to be working fine. I haven't check yet how could this behave for remote data.

Demo plunker

Closes #68

@dimirc
Copy link
Contributor Author

dimirc commented Jul 14, 2014

@ProLoser @tkrotoff what do you think about this feature?

@dimirc dimirc added this to the 0.5.0 milestone Jul 14, 2014
@SimeonC
Copy link
Contributor

SimeonC commented Jul 14, 2014

I wrote some tests over in #108

@willsoto
Copy link

+1 to this. This would be great.

@WhatFreshHellIsThis
Copy link

+1, just came here to find the documentation on how to bind to a single property of an object and didn't even realize it wasn't a feature.

@lowerends
Copy link

How will this work for data that is loaded (for updating existing data for example)? You won't be able to set the ng-model to person.email.

For creating new data, this will be very useful, but for updating existing data, one would still need to pull a trick to get the loaded data in the selected property. Or should this be tackled in a separate issue?

@dimirc
Copy link
Contributor Author

dimirc commented Jul 20, 2014

@lowerends can you explain better the situation? Btw, did you check the Plunker? There is a button that will update the model and I'm not sure if that is what you were referring to.

@lowerends
Copy link

Well, in that Plunker, say you have selected Adam and saved the email address to the database. If you then load the form for editing, thereby loading person.email, I would like to know whether this will populate the dropdown automatically if you set the model to person.email. Or do you need to implement the functionality that the button provides in the Plunker, i.e. setting the person.selected at some point (like explained in the first FAQ)?

@lowerends
Copy link

After looking into it a bit more, it will indeed be possible to set the selected item using the same functionality as the button in the Plunker.

BTW, this PR is a great addition. As soon as it's released, I'll test it against dynamically loaded data as well.

@SimeonC
Copy link
Contributor

SimeonC commented Jul 20, 2014

@lowerends From what I understand what you're asking is if the refresh function (and hence $select.search is set) is called on the ui-select choices with the new value set on the ng-model. The answer is no, not currently - forked plunkr http://plnkr.co/edit/Tj3SVw89qWyivjJz5Iyd?p=preview. (I'm updating a variable to hold the last refresh value sent through).

@dimirc This only would affect when the option reset-search-input="false" is set as otherwise the input and $select.search is cleared anyway on open/close. The fix would be that on ng-model change (the parser I guess) it also sets $select.search to the alias (person.email in example). Though I think this may be an additional feature rather than a fix as it isn't something ui-select does at the moment AFAIK.

@WhatFreshHellIsThis
Copy link

Really anxious for this one; I'm writing a lot of workaround code for it now that I know I'll just have to remove later, any idea when it will be merged and available?

@dimirc
Copy link
Contributor Author

dimirc commented Jul 23, 2014

@WhatFreshHellIsThis should be merged this week, I was just waiting some feedback and want to release v0.5 with other fixes too

@WhatFreshHellIsThis
Copy link

Excellent news, thank you @dimirc!

dimirc added a commit that referenced this pull request Jul 29, 2014
feat(ngModel): bind to single property instead of entire object
@dimirc dimirc merged commit 0fc1f35 into master Jul 29, 2014
@dimirc dimirc deleted the feat-modelmapper branch July 29, 2014 04:17
@dimirc dimirc restored the feat-modelmapper branch August 3, 2014 03:24
This was referenced Aug 5, 2014
@user378230 user378230 deleted the feat-modelmapper branch April 2, 2016 21:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setting chosen property of selected object as ngModel instead of the whole object
5 participants