Do not load data in the picklist (jquery-ui + angularJS)

0

using: link

I can not load data coming from my client table into the picklist. It was already working on another template, changed the template in the company and I'm adapting to the new components. I got this picklist from outside, because the template does not have it.

What could be wrong? I have no idea, just do not load anything on the picklist.

angular.module('BoxApp').controller("CadastroCertificado", function($scope, $http) {

	$scope.clientes = {};
	$scope.listaEmpresas = [];
	
	$scope.iniciar = function() {
		$http.get(urlRestServer + '/cadastrocertificado').success(function(response) {
			$scope.clientes = response;
			
		});
	};

	$scope.iniciar();	
	
	/**
	 * Trabalhando o componente picklist
	 */
    $scope.clientes2 = [];	    
	$scope.atribuirUm = function(index, c) {
		var cliente = {};
		cliente.idCliente = c.idCliente;
		cliente.razaoSocial = c.razaoSocial;
	    $scope.clientes2.push(cliente);
	    $scope.clientes.splice(index, 1);
	};
	$scope.limparUm = function(index, c2) {
	    $scope.clientes2.splice(index, 1);
	    $scope.clientes.push(c2);	    
	};
	
	/**
	 * Trecho para validar o form ao submeter.
	 */
	$scope.submitted = false;
	$scope.submitForm = function(form, clientes2) {		
		$scope.listaEmpresas = $scope.clientes2;
		$scope.submitted = true;
		if (form.$valid) {			
			$scope.cadastraCertificado();
		}
	};	

	/**
	 * Requisição POST (ajax)
	 */
	$scope.cadastraCertificado = function() {
		
		var dados = {
				urlCertificado : $scope.certificadoIncluirAlterar.urlCertificado,
				strDataValidadeCertificado : $scope.certificadoIncluirAlterar.strDataValidadeCertificado.toString(),
				senhaCertificado : $scope.certificadoIncluirAlterar.senhaCertificado,
				listaEmpresas : $scope.listaEmpresas				
		};
		
		$http.post(urlRestServer + '/cadastrocertificado/salvarCertificado', dados).then(function(response) {
			
		}, function(response) {	
			$scope.sucesso();
		});
	};	
	
	$scope.sucesso = function() {
		$scope.closeModal();
		$scope.iniciar();		
	};
	
	$scope.closeModal = function() {
		$('#myModal').modal('hide');
	};

});
<div class="form-group">
    <label class="control-label col-md-3">Empresas:</label>
    <div class="col-md-9">
        <select id="foobar" name="foobar" multiple="multiple">                                             
              <option ng-repeat="c in clientes" value="{{c.idCliente}}" ng-click="atribuirUm($index, c)">{{c.razaoSocial}}</option>
              <option selected ng-repeat="c2 in clientes2" value="{{c2.idCliente}}" ng-click="limparUm($index, c2)">{{c2.razaoSocial}}</option>
        </select>
    </div>
</div>   
    
asked by anonymous 28.01.2016 / 14:26

2 answers

0

It's really complicated to mix jquery with angular, do not recommend, just gave error.

The component was in jquery and I was manipulating with angular because of several internal reasons for the project here in the company.

In short, I made a picklist in the same hand and created the javascript functions to manipulate from side to side.

    
01.02.2016 / 16:28
1

As you are making a request with $http , you are expecting a response with this header:

(data, status, headers, config)

If you get a status positive, that is, with a valid return, the data will be within data . This way you need to access the information there, see:

$scope.clientes = response.data;
    
28.01.2016 / 14:55