I'm using a directive string-to-number in angularjs but it doesn't seem to update the value for my ng-model which is an array. I'm not sure how to use $scope.watch or $apply() with this
My Stackblitz: https://stackblitz.com/edit/angularjs-controllers-v21gd7?file=app.js Here's my directive:
.directive("stringToNumber", function($scope) { return { require: "ngModel", bindToController: true, link: function(scope, element, attrs, ngModel, $parse) { ngModel.$parsers.push(function(value) { return "" + value; }); ngModel.$formatters.push(function(value) { return parseFloat(value); }); } };
});
2.1m questions
2.1m answers
60 comments
57.0k users