Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- @Component({
- selector: 'app-cep',
- templateUrl: './cep.component.html',
- styleUrls: ['./cep.component.sass']
- })
- export class CepComponent implements OnInit {
- constructor() { }
- ngOnInit() {
- }
- }
- let endereco = "";
- let logradouro = "";
- let bairro = "";
- let localidade = "";
- let uf = "";
- declare const require: any
- const axios = require("axios");
- axios.get("https://viacep.com.br/ws/05042000/json/")
- .then(function(response) {
- // handle success
- endereco = response.data;
- logradouro = response.data.logradouro;
- bairro = response.data.bairro;
- localidade = response.data.localidade;
- uf = response.data.uf;
- console.log(logradouro, bairro, localidade, uf);
- })
- .catch(function(error) {
- // handle error
- console.log("erro");
- })
- .finally(function() {
- // always executed
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement