I\'m trying to use ng-options with a to bind a numeric integer value to a list of corresponding options. In my controller, I have something like
Just to add Christophe's answear: easiest way to achive and maintaint it is to make a directive:
JS:
.directive('convertToNumber', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.push(function(val) {
//saves integer to model null as null
return val == null ? null : parseInt(val, 10);
});
ngModel.$formatters.push(function(val) {
//return string for formatter and null as null
return val == null ? null : '' + val ;
});
}
};
});
Christophe's answear wont work correctly for '0' as it returns false on "val?" test.