<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>
时间: 2024-11-10 13:39:07