Advertisement
zerinol

cep.component.ts

Jan 14th, 2020
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2.  
  3. @Component({
  4.     selector: 'app-cep',
  5.     templateUrl: './cep.component.html',
  6.     styleUrls: ['./cep.component.sass']
  7. })
  8. export class CepComponent implements OnInit {
  9.  
  10.     constructor() { }
  11.  
  12.     ngOnInit() {
  13.     }
  14.  
  15. }
  16.  
  17. let endereco = "";
  18. let logradouro = "";
  19. let bairro = "";
  20. let localidade = "";
  21. let uf = "";
  22.  
  23. declare const require: any
  24. const axios = require("axios");
  25.  
  26. axios.get("https://viacep.com.br/ws/05042000/json/")
  27.     .then(function(response) {
  28.         // handle success
  29.         endereco = response.data;
  30.         logradouro = response.data.logradouro;
  31.         bairro = response.data.bairro;
  32.         localidade = response.data.localidade;
  33.         uf = response.data.uf;
  34.         console.log(logradouro, bairro, localidade, uf);
  35.  
  36.     })
  37.     .catch(function(error) {
  38.         // handle error
  39.         console.log("erro");
  40.     })
  41.     .finally(function() {
  42.         // always executed
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement