• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

basic data type mismatch question

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am learning angularJS and javascript.  Have a simple angular ng-options




My problem is actually a data type issue:  I found if I have



then things work, but if it is then there is problem.  So I tried



but it doesn't work either.  Anybody has any idea to fix it ?

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value of a select element is always a string.
 
Linwood Hayes
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:The value of a select element is always a string.



Thanks Bear.  I found $scope.selectedItem is actually the "id" field in my case.  So, suppose I select a value whose "id" is 3, are you saying $scope.selectedItem would return the String value of 3 ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Selects do not possess numeric values; just strings. You'll find that the same is true of radio buttons which we sometimes want to instinctively treat as Booleans, but which does not work.

I usually solve any impedance between the actual model and what the form needs by fronting the model with a "form model" (usually as a wrapper or sometimes a decorator).
 
reply
    Bookmark Topic Watch Topic
  • New Topic