My current issue arises when I click on a button and set a value within the button click method. Despite declaring the variable in the constructor, I am unable to retrieve that value. The code snippet below demonstrates this problem as I keep getting 'undefined' in the constructor:
public dat = {
"pexels-photo.jpeg": {
"information": "laptop",
"desc": {
"mimetype": "image/jpeg",
"id": "shsj44",
"file_id": "pexels-photo.jpeg"
},
"_id": "shsj44"
}
};
fileid= "";
constructor(){
console.log(this.fileid);
// A URL HAS TO BE CALLED HERE WITH FILEID AS PARAMETER;
}
getData(){
Object.keys(this.dat).forEach(key => {
var value = this.dat[key];
// console.log(key +':',value["_id"]);
this.fileid = value["_id"];
console.log(this.fileid);
});
}
You can find my code on StackBlitz here: https://stackblitz.com/edit/angular-dr7ehj
The reason why I declare this variable in the constructor is because I need to leverage its value for obtaining some information within the constructor.