I am filling out a selection of the departments of a company in the following way:
$scope.selectize_a_data = {
options: [
{
id: 1,
title: 'Informatica',
value: 1,
parent_id: 1
},
{
id: 2,
title: 'Contabilidad',
value: 2,
parent_id: 2
}
]
};
options.title what it contains will be what the select will show. But I must do this dynamically, that is, in title I must add a text that comes from a WebService / departments.
I'm doing it in the following way, but I do not know how to insert an object into the options array or what another solution might give it since the structure of the object must be like the previous one.
$http.get('http://localhost:808/sistemaerp/public/ws/departamentos').success(function(datas)
{
angular.forEach(datas.records, function(objeto)
{
console.log(objeto);
$scope.options.push(objeto);
});
$scope.selectize_a_data = {
options: []
};
});
Let's say it looks like this:
$scope.selectize_a_data = {
options: [
{
id: objeto.id,
title: objeto.departamento,
value: 1,
parent_id: 1
}
]
};
Since for each object that the WebService finds, it must be adding values that it contains to the options []
The html I have it this way:
<div class="parsley-row">
<input type="text" config="ConfiguracionesSelect" options="selectize_a_data.options" ng-model="item.estado" name="selectize_a" selectize />
</div>
Solved:
$scope.ObjDepartamento = {};
$scope.departamentos = [];
$http.get('http://localhost:808/sistemaerp/public/ws/departamentos').success(function(datas)
{
angular.forEach(datas.records, function(value, key)
{
$scope.departamentos.push({
id: value.id,
title: value.departamento,
value: value.id,
parent_id: value.id
});
});
});
$scope.ObjDepartamento['departamentos'] = $scope.departamentos;
HTML
<input type="text" config="confDepartamentos" options="ObjDepartamento.departamentos" ng-model="item.iddepartamento" selectize />