I am using angular -ui select2 for a fairly simple dropdown. It was supported by a static dataset sitting on my control area. In my controller, I have a function that is called when the ng changes the drop-down list so that I can perform some actions when the value changes.
However, I found that the ng-model property is set as a JSON string and not the actual javascript object, which makes it impossible to use dot notation to capture the properties of this model.
Here the function that processes the value of the drop-down list changes:
$scope.roleTypeChanged = function() { //fine: console.log('selectedType is: ', $scope.adminModel.selectedType); // this ends up being undefined because $scope.adminModel.selectedType is a // JSON string, rather than a js object: console.log('selectedType.typeCode is: ', $scope.adminModel.selectedType.typeCode); }
Here's the plunker of my complete example: http://plnkr.co/edit/G39iZC4f7QH05VctY8zG
I have never seen a property that is tied to an ng model to do this before, but I'm also pretty new to Angular, so probably I'm just doing something wrong. I can, of course, do something like $ .parseJSON () to convert the JSON string back to an object, but I would prefer, if not necessary. Thanks for any help!
angularjs jquery-select2 angular-ui
Graff vynda-k
source share