CEP - Angular JS

In this example below you will see how to do a CEP - Angular JS with some HTML / CSS and Javascript

Utilizando o webservice do ViaCep(viacep.com.br) para pegar detalhes de um CEP com o Angular JS.

Thumbnail
This awesome code was written by assemany, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright assemany ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>CEP - Angular JS</title>
  
  
  
  
  
</head>

<body>

  <html ng-app="cep">
<head>
	<title>Teste CEP</title>
</head>
<body ng-controller="homeCtrl as home">
<form>
	<label>CEP</label>
	<input type="text" name="cep" id="cep" ng-model="home.cep" />
	<button type="button" ng-click="home.verificarCep()">Verificar CEP</button>
</form>
<div>
	<p>CEP: {{ home.endereco.cep }}</p>
	<p>Logradouro:{{home.endereco.logradouro}}</p>
	<p>Complemento:{{home.endereco.complemento}}</p>
	<p>Bairro:{{home.endereco.bairro}}</p>
	<p>Localidade:{{home.endereco.localidade}}</p>
	<p>UF:{{home.endereco.uf}}</p>
	<p>IBGE:{{home.endereco.ibge}}</p>
</div>
</body>
</html>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/assemany/cep-angular-js-bEqeMy */
	angular.module('cep', []);

	angular
		  .module('cep')
		  .controller('homeCtrl', homeCtrl);

		  homeCtrl.$inject = ['$http'];

		  function homeCtrl($http){
		  	var vm = this;
		  	vm.cep = '';
		  	vm.endereco = {};
		  	vm.verificarCep = verificarCep;

		  	function verificarCep(){
		  		$http.get('https://viacep.com.br/ws/'+ vm.cep +'/json/').then(success, error);
		  	}

		  	function success(data){
		  		vm.endereco = data.data;
		  		console.log(vm.endereco.logradouro);
		  	}

		  	function error(){
		  		console.log('error');
		  	}

		  }

Comments