<!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)的更多相关文章

  1. 秒味课堂Angular js笔记------Angular js中的工具方法

    Angular js中的工具方法 angular.isArray angular.isDate angular.isDefined angular.isUndefined angular.isFunc ...

  2. MysqlDataSource里的Connection实现类实现了isValid(int timeout)方法

    在项目中,需要连接mysql数据库的时候,我们最好选择使用数据库连接池,即需要选择DataSource. 而在使用c3p0的ComboPooledDataSource时,发现它的Connection实 ...

  3. Angular开启两个项目方法

    Angular开启两个项目方法: ng server --port 80

  4. angular基础巩固

    angular中的模块化 //定义模块 []为依赖的模块 moduleName可以使用[]模块中定义的controller filter .. var app=angular.module('modu ...

  5. ionic准备之angular基础——dom操作相关(6)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. angular 基础练习

    <!DOCTYPE HTML> <html> <head> <title> 测试页 </title> <meta charset=&q ...

  7. Angular基础开始

    这个我是想用Angular写一个简单的WebApp,这个是一个简简单单路由: 公共模板--index.html: <!DOCTYPE html> <html ng-app='myAp ...

  8. ionic准备之angular基础———服务provider 和 factory和service(9)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. ionic准备之angular基础——格式化数据以及过滤器(8)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. touchSlider插件案例

    <!doctype html> <html lang="en"> <head> <title>jQuery手机图片触屏滑动轮播效果代 ...

  2. SVN如何进行版本的还原

    http://jingyan.baidu.com/article/d621e8da0d07022865913fa5.html 工具/原料 SVN乌龟软件和相关的文件 百度经验:jingyan.baid ...

  3. python接口自动化7-参数关联【转载】

    本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/python%E6%8E%A5%E5%8F%A3%E8%87%AA%E5%8A%A8%E ...

  4. php7简短而安全的数组遍历方法

    在写 PHP 的数组遍历的时候,我们通常会这样写: foreach ($definition['keys'] as $id => $val) { // ... } 但是其实这样会引起一个重要的问 ...

  5. RANSAC中迭代次数的计算

    假设 $w=\frac{内点个数 }{所有点的个数}$. 则 $p_{0}=w^n$表示采样的$n$个点全为内点的概率(可重复) 则至少有一个为外点的概率$p_{1}=1-p_{0}$ 则重复$K$次 ...

  6. poj1185(状态压缩DP)

    poj1185 题意 给出字母矩阵,只能在字母为 P 的位置放置大炮, 如图所示,每个大炮的射程固定,现在要求尽可能多的放大炮,且使得每个大炮都不在其它大炮的射程内.问最多能放多少. 分析 poj32 ...

  7. 洛谷——P1170 兔八哥与猎人

    P1170 兔八哥与猎人 题目描述 兔八哥躲藏在树林旁边的果园里.果园有M × N棵树,组成一个M行N列的矩阵,水平或垂直相邻的两棵树的距离为1.兔八哥在一棵果树下. 猎人背着猎枪走进了果园,他爬上一 ...

  8. 线程流量控制工具之Semaphore

    简介 Semaphore(信号量)是用来控制同时访问特定资源的线程数量,它通过协调各个线程,以保证合理的使用公共资源.很多年以来,我都觉得从字面上很难理解Semaphore所表达的含义,只能把它比作是 ...

  9. 实现微信朋友圈点击评论按钮时cell上移

    实现场景:微信朋友圈TableView(BigTableView)的每一行cell都包含一个SmallTableView(显示所有点赞及评论) 实现思路: //BigTableView的content ...

  10. Mysql insert without auto-increase when duplicate

    INSERT INTO video_tag_all(tagname,ctime) FROM video_tag_all WHERE (SELECT last_insert_id(id) FROM vi ...