<!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<script src="js/angular.js"></script>
<title></title>
</head>
<body>
<div ng-controller="myCtrl">
请输入留言内容:
<textarea ng-model="user_msg"></textarea>
<br/>
选择喜欢的颜色:
<select ng-model="user_color">
<option value="r">红色</option>
<option value="g">绿色</option>
<option value="b">蓝色</option>
</select>
<br/>
是否同意
<input type="checkbox"
ng-model="user_agree"/>
</div>
<script>
var app = angular.module('myApp', ['ng']);
app.controller('myCtrl', function ($scope) {
console.log('myCtrl func is called');
$scope.user_msg = "";
$scope.user_color='r';
$scope.user_agree = true; $scope.$watch('user_msg', function (newVal,oldVal) {
console.log(newVal);
console.log($scope.user_msg);
}) $scope.$watch('user_color', function () {
console.log($scope.user_color);
}) $scope.$watch('user_agree', function () {
console.log($scope.user_agree);
}) console.log($scope); })
</script>
</body>
</html>

Angular 双向数据绑定的更多相关文章

  1. 第217天:深入理解Angular双向数据绑定的原理

    一.理解angular双向数据绑定 双向绑定是新的前端框架中频繁出现的一个新词汇,也是mvvm的核心原理.angularjs五条核心信念中的数据驱动,便是由双向绑定进行完成. 那么什么是双向绑定,下面 ...

  2. Angular双向数据绑定MVVM以及基本模式分析

    MVVM: angular的MVVM实现的是双向数据绑定,模型从服务器端抓取到数据,将数据通过控制器(controller)传递到视图(view)显示,视图数据发生变化时同样也会影响到模型数据的变化, ...

  3. angular 双向数据绑定与vue数据的双向数据绑定

    二者都是 MVVM 模式开发的典型代表 angular 是通过脏检测实现,angular 会将 UI 事件,请求事件,settimeout 这类延迟的对象放入到事件监测的脏队列,当数据变化的时候,触发 ...

  4. angular双向数据绑定

    <body ng-app> //三个view都会变 <input type="text" ng-model="name" value=&quo ...

  5. 双向数据绑定(angular,vue)

    最近github上插件项目更新了关于双向数据绑定的实现方式,关于angular和vue. angular众所周知是使用的脏检查($dirty).一开始大家会认为angular开启了类似setInter ...

  6. Angular解决双向数据绑定

    <!DOCTYPE html> <html ng-app="myApp1"><body><div ng-controller=" ...

  7. Angular自定义组件实现数据双向数据绑定

    学过Angular的同学都知道,输入框通过[(ngModel)]实现双向数据绑定,那么自定义组件能不能实现双向数据绑定呢?答案是肯定的. Angular中,我们常常需要通过方括号[]和圆括号()实现组 ...

  8. angular,vue,react的基本语法—双向数据绑定、条件渲染、列表渲染、angular小案例

    基本语法: 1.双向数据绑定 vue 指令:v-model="msg" react constructor(){ this.state{ msg:"双向数据绑定" ...

  9. angular和vue双向数据绑定

    angular和vue双向数据绑定的原理(重点是vue的双向绑定) 我在整理javascript高级程序设计的笔记的时候看到面向对象设计那章,讲到对象属性分为数据属性和访问器属性,我们平时用的js对象 ...

随机推荐

  1. HashMap源码调试——认识"put"操作

    前言:通常大家都知道HashMap的底层数据结构为数组加链表的形式,但其put操作具体是怎样执行的呢,本文通过调试HashMap的源码来阐述这一问题. 注:jdk版本:jdk1.7.0_51 1.pu ...

  2. php面试题整理(三)

    判断是不是ie浏览器 1,1

  3. python六十六课——单元测试(二)

    ''' 封装Person类 ''' class Person: def __init__(self,name,age): self.name=name self.age=age def getAge( ...

  4. Unix/Linux环境C编程新手教程(21) 各个系统HelloWorld跑起来效果怎样?

    版权声明:本文为博主尹成联系QQ77025077,微信18510341407原创文章,欢迎转载侵权不究. https://blog.csdn.net/yincheng01/article/detail ...

  5. ubuntu18.04 下 使用conda安装requirement.txt指定的依赖包

    首先创建特定的虚拟环境 conda create -n temp_test python=3.5 conda install anaconda 切换到该环境 conda activate temp_t ...

  6. numpy中矩阵乘法,星乘(*)和点乘(.dot)的区别

    import numpy a = numpy.array([[,], [,]]) b = numpy.array([[,], [,]]) 星乘表示矩阵内各对应位置相乘,矩阵a*b下标(0,0)=矩阵a ...

  7. 转://Oracle数据库补丁分析实践

    小弟我最近做了几次补丁分析,最开始分析补丁,感觉挺痛苦的,因为补丁数量多,且涉及的知识点非常非常的广,客户的要求又非常高.挺伤不起的.不过随着分析的深入,我慢慢的掌握了一些小方法.也在support网 ...

  8. wxWidgets与其它GUI工具库比较

    WxWidgets Compared To Other Toolkits   Some general notes: wxWidgets not only works for C++, but als ...

  9. Spring Security(十八):5.9 Post Processing Configured Objects

    Spring Security’s Java Configuration does not expose every property of every object that it configur ...

  10. node.js之十大Web框架

    之前接触过Node.js是因为好奇大前端越来越能干了,连我后台的饭碗都要抢了,太嚣张了,于是我想打压打压它,然后就这样接触它了.再到后来是因为Settings-Sync插件二次开发,我需要用node. ...