3、AngularJs的双向数据绑定

来源:互联网 发布:ios游戏推荐 知乎 编辑:程序博客网 时间:2024/04/30 18:32

1、AngularJs的指令系统

      • ng-app

      • ng-controller

2、AngularJs的双向数据绑定

          • MVVM
      • $timeout
      • ng-click     (类似于点击事件)
      • ng-model  (绑定一个Model的数据)
3、双向数据绑定
     3.1 双向数据绑定,M影响V
<!DOCTYPE html><html ng-app><head><meta charset="UTF-8"><title>双向数据绑定</title><script type="text/javascript" src="../js/angular.min.js"></script><script type="text/javascript">function Aaa($scope, $timeout) {$scope.age = 10;/*1、利用定时器*//*$timeout(function() {$scope.age = 5;}, 2000);*//*2、利用点击事件*/$scope.show = function() {$scope.age = 5;}}</script></head><body><div ng-controller="Aaa" ng-click="show()">{{age}}</div></body></html>
     3.2  双向数据绑定,V影响M
<!DOCTYPE html><html ng-app><head><meta charset="UTF-8"><title>双向数据绑定</title><script type="text/javascript" src="../js/angular.min.js"></script><script type="text/javascript">function Aaa($scope, $timeout) {$scope.name = 'zhang';}</script></head><body><div ng-controller="Aaa"><input type="text" ng-model="name" /><p>{{name}}</p></div></body></html>

1 0
原创粉丝点击