I’m just getting started with Angular 2 and TypeScript and I can’t seem to figure out how to use callback functions, I know this may be a silly question but given this regular javascript code: “An example of downloading such a photo”
downloadPhoto('http://coolcats.com/cat.gif', handlePhoto);
function handlePhoto (error, photo) {
if (error) console.error('Download error!', error)
else console.log('Download finished', photo)
}
console.log('Download started')
Here as we know three major things happen. First the handlePhoto function is declared, then the downloadPhoto function is invoked and passed the handlePhoto as its callback, and finally ‘Download started’ is printed out.
Note that the handlePhoto is not invoked yet, it is just created and passed as a callback into downloadPhoto. But it won’t run until downloadPhoto finishes doing its task, which could take a long time depending on how fast the Internet connection is.
What is the equivalent in TypeScript?
And Thanks in advance