ionic准备之angular基础——$watch,$apply,$timeout方法(5)
<!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>
ionic准备之angular基础——$watch,$apply,$timeout方法(5)的更多相关文章
- 秒味课堂Angular js笔记------Angular js中的工具方法
Angular js中的工具方法 angular.isArray angular.isDate angular.isDefined angular.isUndefined angular.isFunc ...
- MysqlDataSource里的Connection实现类实现了isValid(int timeout)方法
在项目中,需要连接mysql数据库的时候,我们最好选择使用数据库连接池,即需要选择DataSource. 而在使用c3p0的ComboPooledDataSource时,发现它的Connection实 ...
- Angular开启两个项目方法
Angular开启两个项目方法: ng server --port 80
- angular基础巩固
angular中的模块化 //定义模块 []为依赖的模块 moduleName可以使用[]模块中定义的controller filter .. var app=angular.module('modu ...
- ionic准备之angular基础——dom操作相关(6)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- angular 基础练习
<!DOCTYPE HTML> <html> <head> <title> 测试页 </title> <meta charset=&q ...
- Angular基础开始
这个我是想用Angular写一个简单的WebApp,这个是一个简简单单路由: 公共模板--index.html: <!DOCTYPE html> <html ng-app='myAp ...
- ionic准备之angular基础———服务provider 和 factory和service(9)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ionic准备之angular基础——格式化数据以及过滤器(8)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- CodeForces Round #403 (Div.2) A-F
精神不佳,选择了在场外同步划水 没想到实际做起来手感还好,早知道就报名了…… 该打 未完待续233 A. Andryusha and Socks 模拟,模拟大法好.注意每次是先判断完能不能收进柜子,再 ...
- css 实现高斯模糊
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HDU1083_Courses_课程_C++
给你们人工翻译一下题目哈,刚好练一下英语 对于一个组中有 N 个学生和 P 种课程.每个学生能够参加0种,1种或者更多的课程.你的任务是找到一种可能的方案使恰好P个学生同时满足下列条件: ‧ 方案中的 ...
- [ CodeVS冲杯之路 ] P1068
不充钱,你怎么AC? 题目:http://codevs.cn/problem/1068/ 这是一道神DP题,一开始状态设计错了,用位置和剩余卡片做下标,过了样例数据WA了 好了,讲正解,设 f[i][ ...
- VS2013 MFC C++ CString ,const char , char, string 类型转换
VS2013 测试 以下测试加入头文件: # include <string>#include <cstdlib>using namespace std; //-------- ...
- springBoot【01】
/* 使用spring官网的 http://start.spring.io/ 来建立项目包 生成入口文件,入口文件中对类注释@SpringBootApplication,这个注释是唯一的,标明这个类是 ...
- hiho一下第128周 后缀自动机二·重复旋律5
#1445 : 后缀自动机二·重复旋律5 时间限制:10000ms 单点时限:2000ms 内存限制:512MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为一段数构成的数 ...
- HDU 4034 Graph Floyd最短路
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4034 题意: 给你一个最短路的表,让你还原整个图,并使得边最少 题解: 这样想..这个表示通过floy ...
- Requirement Analysis
BRD:Business Requirements Document,商业需求文档.这是产品声明周期中最早的问的文档,再早就应该是脑中的构思了,其内容涉及市场分析,销售策略,盈利预测等,通常是和老大们 ...
- iOS AudioSession详解 Category选择 听筒扬声器切换
在你读这篇文章之前,如果你不嫌读英文太累,推荐阅读下苹果iOS Human Interface Guidelines中Sound这一章. 选择一个Category AVAudioSessionCa ...