Autocomplete Finder AngularJS + SQL SERVER does not show results

0

I'm doing a search through a DB in SQL Server and AngularJS where at the time of writing you will be suggesting the results (Google type)

The problem is that it does not show me the suggested results, I'm doing it in the following way:

<?php
include("conexion.php");
$con = conexion();


if($_GET['value'] != ""){
$sql="SELECT id_persona,nombre_completo,sexo, calle_no FROM PERSONAS where nombre_completo LIKE '".$_GET['value']."%'";
	$res=sqlsrv_query($con,$sql);

    $array = array();


    while ($row = sqlsrv_fetch_array($res)) {
        $array[] = $row;
    }


    echo json_encode($array);
}

?>
<!DOCTYPE html>
<html ng-app="cargar">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
	<script>

	var appCargar = angular.module('cargar', []);

	appCargar.controller('usuariosController', function($scope, $http){
		$scope.cargausuarios = function(){
			$http({url: "json.php", 
			method: "GET",
			params: {value: $scope.usuario}
			}).then(function(usuarios) {$scope.usuarios = usuarios;});
		}
		//Cuando eliges un usuario lo reemplaza en el campo de texto
		$scope.cambiausuario = function(usuario){
			$scope.usuario = usuario;
			$scope.usuarios = null;
		}
		
	});

	</script>	
</head>
<body>

<div ng-controller="usuariosController">
    <input ng-model="usuario" ng-change="cargausuarios()" placeholder="Buscar usuario" />
    <ul>
        <li ng-repeat="usuario in usuarios">
            <a ng-click="cambiausuario(usuario.nombre_completo)">
                {{ usuario.nombre_completo }}
            </a>
        </li>
    </ul>
</div>
	
</body>
</html>

When I check the elements in Google Chrome if it brings me the JSON, but in {{user.full_name}} it does not show me anything ...

Thanks for your time and help ..

    
asked by Checo 18.09.2017 в 20:16
source

1 answer

1

The% response $http is in the property data . And the error [ngRepeat:dupes] could be that the response of the server is a plain text and not an object json parseado. If that is your case, use JSON.parse to convert it to a JSON object:

$http({url: "json.php", 
    method: "GET",
    params: {value: $scope.usuario}
}).then(function(usuarios) {
    $scope.usuarios = JSON.parse(usuarios.data);
});
    
answered by 18.09.2017 / 21:03
source