0
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;
});
Join Jsfiddle to understand better: https://jsfiddle.net/vosnwb1s/1/
"name": "teste1",
"validation": {
"messages": [
null,
null,
{
"maxlength": ""
}
]
}
I arrived at this solution, but the array is creating null
depending on the place you type in input
text.
I’d like to know how I exclude the objeto
when the value is equal to empty, for example:
{
"maxlength": "Digitado"
}
When the maxlenght: ""
, exclude from the object array...