<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>
var app = angular.module("myApp", ['angularUtils.directives.dirPagination']);
app.controller("myCtrl", function($scope) {
$scope.value=function(){
$scope.users=[{name:abc,email:abc@gmail.com,course:angular js}]
}
</script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<button type="button" ng-click="value()">To get values</button>
<div ng-repeat="user in users">
<input type="text" ng-model="user.name">
<input type="text" ng-model="user.email">
<select ng-model="user.course">
<option value="html">html </option>
<option value="css">css</option>
<option value="angular js">angular js</option>
</select>
</div>
</div>
</body>
我只想在单击按钮时输入值,否则输入值默认为null,直到用户输入文本字段中的值
答案 0 :(得分:0)
初始化函数的数组外部并将值赋给函数内部的数组
var app = angular.module("myApp",[]);
app.controller("myCtrl", function($scope) {
$scope.users=[
{name:'',email:'',course:''}
]
$scope.value=function(){
$scope.users=[{
name:'abc',
email:'abc@gmail.com',
course:'angular js'
}]
}
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<button type="button" ng-click="value()">To get values</button>
<div ng-repeat="user in users">
<input type="text" ng-model="user.name">
<input typee="text" ng-model="user.email">
<select ng-model="user.course">
<option value="html">html </option>
<option value="css">css</option>
<option value="angular js">angular js</option>
</select>
</div>
</div>
&#13;