I'm doing a registration page, and I need to relate a collaborator to a company, but for this I need when the page loads I already have a companies in a list >
I'm already getting businesses in a list, problem and make the object companies be loaded as soon as the page loads.
This is my Angular function:
$scope.colaborador = {};
$scope.empresas = {};
//Lista todas empresas para cadastro do colaborador
$scope.getEmpresas = function () {
var url = "cadastro-colaborador-empresa";
MainService.get(url).then(function (cb) {
location.href = 'cadastro-colaborador';
$scope.empresas = cb;
});
};
$scope.cadastrarColaborador = function () {
var url = 'cadastra-colaborador';
MainService.post(url, {colaborador: $scope.colaborador}).then(function (cb) {
if (cb.idPessoa !== undefined) {
location.href = 'index';
$scope.colaborador = {};
$scope.empresas = {};
} else {
$scope.alertaErro = cb;
$("#myAlert").show();
}
});
};
I'm using vRaptor and Java as well, the function cadastra-colaborador-empresa
returns the company list for the business object.
I tried to call the page so <a href="${pageContext.request.contextPath}/administrador/cadastro-colaborador" ng-click="getEmpresas()">Cadastrar Colaborador</a>
But it did not work, my select is like this
<select ng-options="empresa.idEmpresa as empresa.nome for empresa in empresas" ng-model="colaborador.empresa"></select>
The idea is to have the companies loaded in this select, if anyone has an idea how to do it, I'll be grateful.