Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

ngSelected not updated with ngModel (parentheses weird behavior) #6528

Closed
MBing opened this issue Mar 3, 2014 · 4 comments
Closed

ngSelected not updated with ngModel (parentheses weird behavior) #6528

MBing opened this issue Mar 3, 2014 · 4 comments

Comments

@MBing
Copy link

MBing commented Mar 3, 2014

I haven't found something similar to this problem. If there is, my apologies and please redirect me.

See this for an example of my problem:
http://plnkr.co/edit/Eu49n2tTB3IQYSaNLQDt

So as you can see I have the ngModel defined in ngSelected and gave it the number 5 (now it is default in my controller, but in my own example it is updated automatically, but this reflects the same problem I am having and was easier to explain/show)

this is noted as:
ng-selected="referenceNumber)"
You can also put this as:
ng-selected="(referenceNumber"
and it will also select the correct value given in the model.

But if I where to put no parentheses or other brackets in place or just open
and close it with parentheses, the ngSelected directive is not recognizing the value
and it will default to 0.

Is there's something I am missing or have misinterpreted while making this, which brings me to this unreasonable solution? I know there is ngOptions as a directive to use, but this solution worked and it was closest to what I wanted to accomplish.

Thank you!
Martin

@joshkurz
Copy link
Contributor

joshkurz commented Mar 3, 2014

I'm not sure why the ")" thing is working, but you do not need ngSelected when using a select element in this manner. Just setting the model will init the select box with the desired result.

http://plnkr.co/edit/inn2bhecK0fyiLhsVdph?p=preview

@MBing
Copy link
Author

MBing commented Mar 3, 2014

Thanks @joshkurz ! I noticed if I wanted to use another model to specify the ngSelected, this is not working, so why is there even the ngSelected directive when you can only use the ngModel to be the selected value.

I think the value with only 1 parenthesis is working because it is not executed as it is not valid. So it skips it and it keeps the solution you just gave.
Make's sense?

@joshkurz
Copy link
Contributor

joshkurz commented Mar 3, 2014

Yes that makes sense...

I believe one of the main reasons for ngSelected is to set default values depending upon if the model is not set correctly. http://plnkr.co/edit/xXq3b40nvqkjPlyCxZNG?p=preview

@MBing
Copy link
Author

MBing commented Mar 3, 2014

Ah that makes it all clearer now, thanks for the help!

@MBing MBing closed this as completed Mar 3, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants