<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>angular.js</title>
</head>
<body>
<div ng-app = "" ng-controller="mycontrol">
<h3>firstName:</h3>
<input type = "text" ng-model="user.firstname">
<h3>lastName:</h3>
<input type = "text" ng-model = "user.lastname">
<button ng-click="reset()">reset</button>
<p>form: {{user}}</p>
<p>master: {{master}}</p>
</div>
<script>
function mycontrol($scope){
$scope.master = {
firstname: "zhao",
lastname: "yuxa"
};
$scope.reset = function () {
$scope.user = angular.copy($scope.master);
}
/*$scope.reset();*/
}
</script>
<script src = "../angular.js/angular.min.js"></script>
</body>
</html>为什么在<script> 中,我去掉加注释的那一部分,刚开始浏览器中表格里面就没有内容呢??是执行顺序的事儿吗?求解答
1 回答
已采纳
woshiajuana
TA贡献211条经验 获得超152个赞
$scope.reset = function () {
$scope.user = angular.copy($scope.master);
}
这个是将函数
function () {
$scope.user = angular.copy($scope.master);
}的指针存于 $scope.reset 变量上
相当于var fun=function(){},声明一个fun函数
/*$scope.reset();*/ 这个是函数调用
你都没有调用函数, 那$scope.user的属性当然就会没有值呀
添加回答
举报
0/150
提交
取消