失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > angular的watch监听

angular的watch监听

时间:2022-08-29 07:35:26

相关推荐

angular的watch监听

watch比较消耗性能,所以用完后就要消除监听

<!DOCTYPE html><html><head><meta charset="utf-8" /><title>作用域</title><script src="js/angular.min.js"></script><style type="text/css"></style></head><body ng-app="my-frist-app"> <div id="box" ng-controller="fristController" >商品数量:<input type="text" ng-model="count"/>商品单价:<input type="text" ng-model="price" />商品总价:{{count*price}}邮费:{{youFei}}总计:<p ng-bind="total"></p></div><script type="text/javascript">var myApp = angular.module('my-frist-app',[])// $watch 监听方法,监听变化myApp.controller('fristController',function($scope){//$scope.$watch('price*count',function(){//console.log("fuji")//});var watch = $scope.$watch('price',function(newValue,oldValue,$scope){console.log(newValue);console.log(oldValue)})// 销毁监听// watch();});</script></body></html>

如果觉得《angular的watch监听》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。