<body> <div ng-app= "myApp" > <div ng-controller= "Firstcontroller" > <p> Price: <i Nput type= "text" ng-model= "Iphone.money" ></p> <p> number: <input type= "text" ng-model= "Iphone.num" & Gt;</p> <p> Fee: <span>{{sum () | currency: ' ¥ '}}</span></p> <p> Freight: <span>{{iphone.fre | Currency: ' ¥ '}}</span></p> <p> total: <span>{{sum () + Iphone.fre | Currency: ' ¥ '}}</span></p> </div> </div> <script type= ' Text/javascript ' >varApp = Angular.module ("myApp", []); App.controller (' Firstcontroller ', [' $scope ',function($scope) {//Object Definition$scope. iphone ={money:5, Num:1, Fre:10 }; //Calculate total and number$scope. Sum =function () { return$scope. Iphone.money *$scope. Iphone.num; } //If the total price is greater than 100, freight becomes 0 can listen function, can also directly listen to object properties$scope. $watch ($scope. Sum,function(newvalue,oldvalue) {$scope. Iphone.fre= newvalue >= 100? 0:10; }); }]); </script></body>
Angularjs-watch Listener Object