Main function, which will return the value chave = data.chave
:
var chave = '';
$scope.submitForm = function() {
$http({
method : 'POST',
url : 'validar.php',
dataType: 'json',
data : dados,
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data) {
if (data.errors) {
$scope.erro = data.errors.errovalidar;
} else {
chave = data.chave;
$('#imprimir-danfe').removeAttr('disabled');
}
})
};
Secondary function, which should take as the parameter the value returned from the main function ( chave
):
var imprimir_d = document.getElementById('imprimir');
imprimir_d.addEventListener('click', function() {
$http({
method : 'POST',
url : 'imprimir.php',
data : chave,
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
})
});
However, the way it is, when I do console.debug(chave)
, inside the secondary function and returned " undefined
"