1.理论知识
- ng-model: 双向数据绑定
- ng-bind: 单向数据绑定,等价于{{}}
2. ng_model.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello AngularJS</title>
<meta name="keywords" content="HelloWorld" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" name="viewport">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<script src="js/common/angular.min.js"></script>
<script src="js/common/angular-ui-router.min.js"></script>
</head>
<body ng-app="notesApp" ng-controller="MainCtrl as ctrl">
<input ng-model="ctrl.helloMsg">
<br>
{{ctrl.helloMsg}} AngularJS
</body>
<script type="text/javascript">
angular.module('notesApp',[])
.controller('MainCtrl', [function(){
var self = this; //this指向MainCtrl实例
self.helloMsg = 'dear';
}]);
</script>
</html>
3. 展示页面
初始加载
输入及时更新
网友评论