您的位置:首页 > Web前端 > AngularJS

Angular自动双向绑定值

2015-04-24 10:38 393 查看
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div ng-app="myApp" ng-controller="formCtrler">
<form novalidate>
Name:<br>
<input type="text" ng-model="user.Name"><br>
Email:<br>
<input type="text" ng-model="user.Email">
<br>
<br>
<button ng-click="reset()">
RESET</button>
</form>
<p>
form = {{user }}</p>
<p>
master = {{master}}</p>
</div>
</body>
<script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.2.15/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller("formCtrler", function ($scope) {
$scope.master = { "firstName": '123', "lastName": '456' };

$scope.reset = function () {
$scope.user = angular.copy($scope.master);
};
//注册事件之后调用为model赋值
$scope.reset();
});
</script>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: