(监听一个模型中,当一个模型每次改变时,都会触发第二个函数)
看美元(watchFn, watchAction deepWatch)
带有角表达式或者函数的字符串,它会返回被监控的数据模型的当前值。
一个函数函数(newValue oldValue){},当watchFn发生变化时会被调用
默认为false,监听数组的某个元素或者对象的属性时设置为真;
& lt; !DOCTYPE html> & lt; html> & lt; head> & lt;元charset=" utf - 8 "/比; & lt;/head> & lt; body> & lt; div ng-app=ng-controller“myApp”=癿yCtrl”比; & lt; form> 祝辞& lt; div class="形式的班级”; & lt;输入ng-model=" name "/在{{名称}} & lt; p>改变次数{{数}}& lt;/p> & lt;/div> & lt;/form> & lt;/div> & lt;脚本src=" http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js "祝辞& lt;/script> & lt;脚本type=" text/javascript祝辞 应用var=角。模块(“myApp”, []); app.controller (myCtrl,函数(范围){ 美元scope.name='橘子”; 美元的范围。数=0; 美元的范围。看美元(“名字”,函数(newValue oldValue) { 美元scope.count + +; 如果美元范围。数在5){ 美元scope.name='苹果”; } }); }); & lt;/script> & lt;/body> & lt;/html>
& lt; !DOCTYPE html> & lt; html> & lt; head> & lt;元charset=" utf - 8 "/比; & lt;/head> & lt; body> & lt; div ng-app=ng-controller“myApp”=癿yCtrl”比; & lt; form> 祝辞& lt; div class="形式的班级”; & lt;输入ng-model=" Data.name "/在{{Data.name}} & lt; p>改变次数{{数}}& lt;/p> & lt;/div> & lt;/form> & lt;/div> & lt;脚本src=" http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js "祝辞& lt;/script> & lt;脚本type=" text/javascript祝辞 应用var=角。模块(“myApp”, []); app.controller (myCtrl,函数(范围){ 美元的范围。Data=https://www.yisu.com/zixun/{名称:“橘子'}; 美元的范围。数=0; 美元的范围。看美元(“数据”,函数(newValue oldValue) { 如果(newValue=https://www.yisu.com/zixun/=oldValue) 返回; 美元scope.count + +; 如果美元范围。数> 5){ 美元scope.Data.name='苹果”; } },真正的); }); & lt;/script> & lt;/body> & lt;/html>
以上这篇关于角js_美元看监控属性和对象详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。