Angular JS update input field after change

前端 未结 5 1583
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 20:26

I\'m trying to build a simple calculator in Angular in which I can override the total if I want. I have this part working but when I then go back to enter in a number in fields

5条回答
  •  执念已碎
    2021-01-30 21:07

    I'm guessing that when you enter a value into the totals field that value expression somehow gets overwritten.

    However, you can take an alternative approach: Create a field for the total value and when either one or two changes update that field.

  • Total {{total}}
  • And change the javascript:

    function TodoCtrl($scope) {
        $scope.$watch('one * two', function (value) {
            $scope.total = value;
        });
    }
    

    Example fiddle here.

提交回复
热议问题