-1
I wonder if it is possible to call a function within a given event using addeventlistener().
I have this function, which adds a reward to the database :
//Função que adiciona uma recompensa ao banco de dados
addReward(){
if(!this.isEditing){
this.addDocument(this.caminho, this.recompensa).then(()=>{
//this.loadData();//refresh view
});
}else{
this.updateDocument(this.caminho, this.recompensa.key,
this.recompensa).then(()=>{
this.loadData();//refresh view
});
}
this.isEditing = false;
//clear form
this.recompensa.valor;
this.recompensa.data;
}
here I have the function that displays a particular ad to the user, I need that when the user closes the video, the above function is executed by sending the value of its reward to the database, but always returns me an error :
videosInmobi() {
let carregar = this.loading.create({content : "Carregando..."});
carregar.present();
let rewardConfig: AdMobFreeRewardVideoConfig = {
isTesting: true,
autoShow: true,
id: 'ca-app-pub-8000726989219599/6974786599' //id videos InMobi
};
this.admob.rewardVideo.config(rewardConfig);
this.admob.rewardVideo.prepare().then((result) => {
carregar.dismissAll();
this.recompensa.data = moment().format('L');
this.recompensa.valor = 0.03;
//tento fazer assim atualmente, porém ele sempre retorna um erro quando fecho o vídeo
document.addEventListener('admob.rewardvideo.events.CLOSE', function(event) {
console.log(event)
this.addReward(this.recompensa);
})
}), carregar.dismissAll();
}
the error that returns me is from the image below :
Thank you so much for the explanation. However if I try to put only addReward(this.reward). It returns me a syntax error, and even allows me to run the application to test. I’m working on Ionic, so I’m calling it through this, if not it returns me just this syntax error. Testing the console.log, I got a #Document on the console when printing this.
– Diego Estacho
I have zero experience in Ionic but found a link that might help.
– Vitor Paladini
Thank you very much, I will check this link. This seems to be exactly what I need. Thanks for the help and availability.
– Diego Estacho