0

I have been working with a select option box. I am able to get it to work and print the selected option correctly independently but inside my application it just would not work.

<select ng-model="selected1" ng-change="operateOnOptions()">
                                <option value='1'>TOPPER</option>
                                <option value='2'>RSC</option>
                                <option value='3'>SPD</option>
                                <option value='4'>SFT</option>
                                <option value='5'>LMP</option>
                            </select>

And my controller is

$scope.operateOnOptions = function(){
console.log($scope.selected1);
};

Now inside my application this will not work no matter what and keeps on printing

Object {$$hashKey: "00S"} What does that weird thing mean??

user3799365
  • 1,087
  • 4
  • 17
  • 27

1 Answers1

1

Object {$$hashKey: "00S"} given your console.log($scope.selected1) statement, means that $scope.selected1 value is currently an object and this object has a single property of $$hashKey with value 00S. Angular typically assigns a $$hashKey property to keep track of certain things, the $$ indicates this as an Angular internal private property.

Now how this relates to your problem, I suspect somewhere in your code you are setting the value of $scope.selected1 to a value that is not one of the given select options values.

Without seeing more of your code, or even better, providing a link to a basic jsfiddle or plnkr repro there's not much more to offer you here.

Beyers
  • 8,968
  • 43
  • 56
  • Thanks I got it to work when I isolated the code as I provided above which works completely. My application is too large to put it on fidle and I cannot do it legally either. But your answer is highly appreciated. – user3799365 Aug 12 '14 at 21:50
  • I am initializing the variable inside my controller using $scope.selected1 = {}; Wonder if that is a problem – user3799365 Aug 12 '14 at 22:01
  • Yes, your initialization is setting selected1 to an empty object and that is why you are seeing that log. The value of selected1 should match one of your select option values. Either set it to null, or to one of the select option values, e.g. 1 – Beyers Aug 12 '14 at 23:42
  • I tried setting it to {} and null and it worked in an independent project but for the life of me I cannot get it to take the selected option value and pass it to the controller. – user3799365 Aug 13 '14 at 13:26
  • Here is the plunker for the independent project I created which works fine http://plnkr.co/edit/isi4p7TKcysICki4m4aK?p=preview – user3799365 Aug 13 '14 at 13:36
  • @user3799365 that doesn't help. Show us a plunker of an example that does NOT work :) – Beyers Aug 13 '14 at 14:57
  • It's a giant application which has the exact same code, but its company's code and therefore cannot show. : (. I was wondering if there is something else I should be doing from what I am doing in the code I put on plunked like with ng-model or ng-selected – user3799365 Aug 13 '14 at 15:29