Set resulting text on a P tag

0

I have the result of a promise that if I execute this, it takes me as a console to the result I want:

web3.eth.getBalance(localStorage.getItem('address')).then(
    console.log
);

But when I try to put the value in a P-label, nothing appears. How should I mount this sentence right?

web3.eth.getBalance(localStorage.getItem('address')).then(
    $('#balance').text()
);
    
asked by Eduardo 17.12.2018 в 12:18
source

1 answer

3

The promises wait for a function as the first parameter, in the first example with the console.log you are passing a function, in the second with the $('#balance').text() you are passing the result of the execution of a function, which can or not be a function, in this case it is not. What you could do is the following:

web3.eth.getBalance(localStorage.getItem('address')).then(function(text){
  $('#balance').text(text)
});
    
answered by 17.12.2018 в 12:26