Skip to content

Instantly share code, notes, and snippets.

@alexalannunes
Created October 6, 2019 14:33
Show Gist options
  • Save alexalannunes/6803bff99149cd8ddab036e4eeab25ed to your computer and use it in GitHub Desktop.
Save alexalannunes/6803bff99149cd8ddab036e4eeab25ed to your computer and use it in GitHub Desktop.
angular
.module('home', [])
.controller('home_ctrl', function ($scope, $q, $http) {
$scope.title = 'Home';
let vm = $scope;
let cancelador = $q.defer();
vm.buscar = () => {
const request = $http.get('http://127.0.0.1:8081/index', { params: { de: 1 }, timeout: cancelador.promise });
var promise = request.then(
response => {
console.log('ok')
},
error => {
console.warn('Errr')
}
);
};
vm.cancelar = () => {
cancelador.resolve();
cancelador = $q.defer();
};
vm.$on('$routeChangeStart', () => {
vm.cancelar()
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment