Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

AngularJS not updating ng-model value with directive

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);
    });
  }
};

});

question from:https://stackoverflow.com/questions/65640751/angularjs-not-updating-ng-model-value-with-directive

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...