我想问一下,如何在用户点击按钮后使用push()添加数据。有人能帮助我吗?
{{1}}
答案 0 :(得分:0)
form
应该是一个数组(数组有push
方法)。它是这样的:
HTML:
<div ng-controller="MyCtrl">
<input type="text" data-ng-model="comName" />
<input type="text" ng-model="comAddress" />
<input type="text" ng-model="nameStaff" />
<input type="text" ng-model="idStaff" />
<button ng-click=addDetail()>add
</button>
</div>
JS:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.form = [{
companyName: "company1",
companyAddress: "company address",
staff: [{
name: "men",
id: "123"
}]
}]
$scope.addDetail = function() {
$scope.form.push({
companyName: $scope.comName,
companyAddress: $scope.comAddress,
staff: [{
name: $scope.nameStaff,
id: $scope.idStaff
}]
});
}
}