HTML
<div ng-app="app">
<div ng-controller="testeCtrl">
<ul ng-repeat="(keyColumn, column) in columns">
<li>{{ column.name }}
<div ng-repeat="method in requireMethods">
<input type="text" class="form-control" ng-model="column.validation.messages[$index][method]" />
</div>
</li>
</ul>
<pre>{{ columns | json }}</pre>
</div>
</div>
Angularjs
var app = angular.module('app',[]);
app.controller('testeCtrl',function($scope){
var requireMethods = ['required','remote','maxlength']
$scope.columns = [{
name: 'teste',
validation: {
messages: []
}
},
{
name: 'teste1',
validation: {
messages: []
}
},
];
$scope.requireMethods = requireMethods;
});
Enter the Jsfiddle to better understand: link
"name": "teste1",
"validation": {
"messages": [
null,
null,
{
"maxlength": ""
}
]
}
I came up with this solution, but the array is creating null
depending on the place you type in input
text.
I would like to know how to exclude objeto
when the value is equal to empty, for example:
{
"maxlength": "Digitado"
}
When maxlenght: ""
, delete from array of objects ...