I am entering with a zip and a search is done and brings me the other data ... However, I want the data to be displayed, each in its own field, as it will be inserted into the database. How to proceed?
html:
<body ng-controller="appController">
<div align="center">
<form>
<table width="100">
<label>CEP </label><br>
<input type="text" ng-model="endereco.cep" ng-blur="pegaCep()"><br>
<label>Estado </label><br>
<input type="text" ng-model="endereco.uf"><br>
<label>Cidade </label><br>
<input type="text" ng-model="endereco.cidade" size="30"><br>
<label>Bairro </label><br>
<input type="text" ng-model="endereco.bairro" size="30"><br>
<label>Rua </label><br>
<input type="text" ng-model="endereco.logradouro" size="30"><br>
</table>
</form>
</div>
</body>
controller:
app.controller('appController', function ($scope, $http){
$scope.endereco = {}
$scope.pegaCep = function () {
$http.get("php/pegaCep.php?cep="+$scope.endereco.cep).success(function (endereco){
console.log(endereco);
$scope.endereco = endereco;
});
}
});
php:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
$cep = $_GET['cep'];
//print_r($cep);
include('correios.class.php');
if(isset($_GET['cep'])){
$correios = Correios::cep($_GET['cep']);
$correios = json_encode($correios[0]);
die($correios);
}elseif(isset($_GET['codigo_rastreio'])){
die(json_encode(Correios::rastreio($_GET['codigo_rastreio'])));
}else{
die('informe parametro GET cep ou codigo_rastreio');
}
?>