I have the following function:
redirect() {
this.afs.collection('links').doc(this.path).ref.get().then(function(doc) {
if(doc.exists) {
// define data and clicks
var data = doc.data();
var clicks = doc.data().clicks;
// Update clicks
doc.ref.update({
'clicks': (clicks + 1)
})
.then(function() {
if(data.landing == false) {
// Redirect to url
return false;
} else {
// Stay for Landing Page
return true;
}
});
} else {
this.router.navigate(['/404']);
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
}
When I try the following in onNgInit:
console.log(this.redirect());
It returns undefined. I'm not sure what to do to either be able to set a value to true or false to return true or false.