ionic准备之angular基础——$watch,$apply,$timeout方法(5)
2016-03-25 18:14
579 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body ng-app="myApp"> <!--$watch用法--> <div ng-controller="firstController"> 数量:<input type="text" ng-model="amount"><br> 价格:{{price}}<br> 总计:{{sum}}<br> </div> <!--apply用法--> <div ng-controller="secondController">{{num}}</div> <!--$timeout用法--> <div ng-controller="threeController">{{num}}</div> </body> <script src="angular/angular.js"></script> <script type="text/javascript"> var app=angular.module("myApp",[]); app.controller('firstController',function($scope){ $scope.amount=123; $scope.price=20; $scope.sum= $scope.amount*$scope.amount; $scope.$watch('amount',function(newValue,oldValue){ //更新amount变化 $scope.sum=newValue*$scope.price; }); }) /*$apply用法*/ app.controller('secondController',function($scope){ $scope.num=20; setTimeout(function(){ $scope.num=30; $scope.$apply(); /*更新view*/ },1500); }) /*$timeout用法*/ app.controller("threeController",function($scope,$timeout){ $scope.num=20; $timeout(function(){ $scope.num=30; },1200); }); </script> </html>
相关文章推荐
- iOS App性能优化
- App架构经验总结
- Nagios监控ESXI主机系统、硬件、nagios日志文件时间格式转换
- iOS学习之路(二)--基础篇
- Html5嵌入app后通过JS和ios以及android客户端交互
- ApplePay测试开发心得
- RecyclerView的BaseAdapter的用法与条目监听的书写
- 不接入微信sdk,在APP中实现微信分享,支付
- android 静默升级成功
- iOS存储数据字典到沙盒
- iOS自适应布局之Masonry(一)
- ios address book 操作大全
- 刚安装的ios app 会带有教你功能使用的特效说明 做法
- iOS开发如何实现版本更新
- iOS开发小记:初次接入环信SDK3.0时遇到的问题及解决办法汇总
- springmvc注解中的@requestmapping
- unity3d,声音播放
- iOS中构造函数与析构函数
- 安卓GridView(自定义适配器)
- Android 官方命令深入分析