$scope.$watch 小例子
来源:互联网 发布:js设置隐藏显示 编辑:程序博客网 时间:2024/06/13 03:15
<!DOCTYPE html><html lang="en" ng-app="HelloApp"> <head> <meta charset="utf-8"> </head> <body> <table border="1" ng-controller="WorldController"> <tr> <td>用户名</td> <td><input type="text" ng-model="user.username"></td> </tr> <tr> <td>密码</td> <td><input type="password" ng-model="user.password"></td> </tr> <tr> <td></td> <td><input type="button" ng-click="login()" value="登录"></td> </tr> <tr> <td></td> <td>{{message}}</td> </tr> </table> <script src="bower_components/angular/angular.js"></script> <script> //创建一个模块 var app = angular.module('HelloApp',[]); //为这个模块创建一个控制器 app.controller('WorldController',['$scope',function($scope){ //$scope.username=''; //$scope.pasword=''; //数据 $scope.user = { username:' ', password:'' }; //行为数据 $scope.login = function(){ //因为数据的变化是双向的同步,所以界面上的值变化会同步到$scope,user上 console.log($scope.user); }; //请输入用户名 输入格式合不合法 $scope.message = "请输入用户名"; //$scope.message取决于$scope.user //监视模型的变化 //官方的API中提供了一个$scope.$watch方法 $scope.$watch('user.username',function(now,old){ console.log('now:'+now); if(now){ if(now.length<7){ $scope.message = '不对'; }else{ $scope.message= ' '; } }else{ $scope.message = '还是不对'; } },true); }]); </script> </body></html>
0 0
- $scope.$watch 小例子
- $scope.$watch
- ionic 中的 $scope.$watch 问题
- Angular中$scope的$watch
- angularJS<六、$scope里的$watch方法>
- AngularJS $watch root scope variable for changes
- angularjs $scope.$watch 遇到的问题
- angularJS<$scope里的$watch方法>
- watch命令及使用例子
- javascript作用域scope例子
- Angularjs $scope 里面的$apply方法 和 $watch方法
- angularJS $scope的$watch方法监听model改变
- Angularjs $scope 里面的$apply 方法 和 $watch 方法
- [angular]服务之2$scope之$watch、$watchGroup、$watchCollection
- AngularJs学习笔记(4)--$scope里的$watch方法
- angular attrs.$observe和$scope.$watch的区别
- AngularJS 学习笔记(2)-MVC,$scope,$watch
- AngularJS中$scope.status(排序例子)
- 设置vim支持Markdown
- CopyOnWriteArrayList实现原理
- Spring中基于Java的配置@Configuration和@Bean用法
- RPG Develop Diray
- 2016年蓝桥杯A组java第七题
- $scope.$watch 小例子
- nmap 基本使用
- 【Java基础】线程和并发机制
- javascript中的表单事件
- java字符串常用操作(查找、截取、分割)
- Android之蓝牙编程开发详解
- 阿里巴巴Java开发规范手册
- 【机房重构】登录问题集锦
- Linux下MongoDB的安装,通过配置文件启动Mongodb的方式研究,mongodb自启动脚本(Linux),Windows下安装MongoDB服务