我想創建動態表單字段後點擊添加行按鈕。動態創建添加表單點擊添加按鈕在angularjs
<form name="form" class="form-validation form-inline" >
<div class="form-group">
{!!
Form::text('name',null,['class'=>'form-control','placeholder'=>'Name','data-ng-model'=>'name','required'=>'required'])
!!}
{!!
Form::text('description',null,['class'=>'form-control','placeholder'=>'Description','data-ng-model'=>'description'])
!!}
</div>
<div class="form-group">
<button class="btn btn-default " ng-disabled="form.$invalid"
data-ng-click="addTag()">
Add
</button>
</div>
添加行
<div ng-repeat="input in form">
<form name="form" class="form-validation form-inline">
<div class="form-group">
{!!
Form::text('name',null,['class'=>'form-control','placeholder'=>'Name','data-ng-model'=>'input.name','required'=>'required'])
!!}
{!!
Form::text('description',null,['class'=>'form-control','placeholder'=>'Description','data-ng-model'=>'input.description'])
!!}
</div>
<div class="form-group">
<button class="btn btn-default " ng-disabled="form.$invalid"
data-ng-click="addTag()">
Add
</button>
</div>
</form>
</div>
而且控制部分等之後編輯。 我應該如何將它們添加到數據庫中? Angularjs控制器:
$scope.addTag = function() {
var tag = {
name: $scope.name,
description: $scope.description
};
$http.post('tags', tag)
.success(function (data) {
console.log('www.sabin.info.np');
$scope.tags = data;
$scope.name = '';
$scope.description = '';
}).error(function (err) {
console.log('error');
});
};
和代碼,我已編輯的是:
$scope.form = [];
$scope.addRow = function() {
$scope.form.push({
name: '',
description: ''
});
}
看到這個答案http://stackoverflow.com/questions/ 32470928/angular-formly-adding-form-fields-dynamic-on-user-click/35603088#35603088 –