0
I am making a registration page, and I need to relate a collaborator to a company, but for that I need when the page load I already have a companies in a list>
I’m already getting the companies on a list, problem and make the companies object to be loaded as soon as the page loads.
This is my function of Angular:
$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 too, the function cadastra-colaborador-empresa
returns the company list for the enterprise object.
I tried to call the page so <a href="${pageContext.request.contextPath}/administrador/cadastro-colaborador" ng-click="getEmpresas()">Cadastrar Colaborador</a>
But it didn’t work, my select this way
<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,.
Why don’t you call the function
$scope.getEmpresas()
on your controller?– DiegoAugusto
I’m starting in Angular and javascript I don’t know much, so within the angular controller itself I can already call the function ? I’ll try here.
– William Cézar