New to Angular - Computed Variables

前端 未结 7 1517
一个人的身影
一个人的身影 2021-02-04 00:33

I am moving to Angular from Knockout, and I have a few issues. I\'m assuming that I must be doing something a non-angular type of way.

http://jsfiddle.net/LostInDaJungle

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 01:22

    For a calculated field, add a method to your controller . . .

    $scope.cost = function() { return $scope.val1 + $scope.val2 };
    

    and then bind to it directly. It will know when it needs to recalculate as its constituent values change.

    {{cost()}}

提交回复
热议问题