Thanks Mr. Elias,
ng-change solves my problem!

Best regards!

Andrea

Il giorno martedì 21 aprile 2015 14:30:08 UTC+2, Andrea Dompè ha scritto:
>
> Hello guys,
>
> i've a problem with $watch() and ng-model,
>
> i have to fill a <select></select> with a json like this 
>
> [{ "tipo" : "A", "label" : "ADMIN" },
>  { "tipo" : "I", "label" : "INFO" },
>  { "tipo" : "S", "label" : "SHOP" },
>  { "tipo" : "C", "label" : "CLIENT" },
>  { "tipo" : "M", "label" : "MANAGER" }]
>
> I have no problem to get and fill the select tag, but i can't retrieve 
> right data from the $scope.watch() function
>
> i always get undefined as selected value.
>
> Follows my example code
>
> <!DOCTYPE html>
> <html ng-app="myTestApp">
> <head>
>  <title>Test</title>
>  <script src="
> https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js";
> ></script>
>  <script>
>  var myTestApp = angular.module('myTestApp', []);
>
>  myTestApp.factory('UserType', function($http) {
>     return {
>         listall: function (callback) {
>             $http.post("../club_members/includes/dbwrapper.php", { cmd:
> 'gettype' }).success(callback); }
>         }
>  }); 
>
>  myTestApp.controller('ListCtrl', function ($scope, UserType){ 
>
>  UserType.listall(function(list){
>   $scope.usertype = list; 
>   console.log(list);
>  }); 
>
>  $scope.$watch('type', function(newValue, oldValue){
>   console.log('newValue=>' + newValue + ' oldValue=>' + oldValue);
>   if(!angular.isUndefined(newValue) || newValue === null) {
>   //...
>   }
>  });
>
>  });
>  </script> 
> </head>
> <body ng-controller="ListCtrl">
>  <select class="form-control" ng-model="type" ng-init="type = ''" 
>     ng-options="item.tipo as item.label for item in usertype | 
> orderBy:'toString()'"></select> 
> </body>
> </html>
>
> Thanks in advance
>
>
> Andrea
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to