In the ngOnInit() mehtod, I'm getting an HTMLElement and using it to set a variable:
ngOnInit(){
this.popUpContainerDisplay = document.getElementById('popUpContainer');
console.log("pop", this.popUpContainerDisplay);
this.popUpAcceptContainerDisplay = document.getElementById('acceptPopUp');
this.popUpDeclineContainerDisplay = document.getElementById('declinePopUp');
this.popUpWarningContainerDisplay = document.getElementById('warningPopUp');
}
popUpFadeOut(): void{
if(this.popUpContainerDisplay.style.opacity == "0"){
console.log("fine", this.popUpContainerDisplay);
this.popUpContainerDisplay.style.opacity = "1";
this.popUpContainerDisplay.style.display = "block";
setTimeout(this.fade, 1000); //popup box fades away after 1 seconds
}
}
fade(): void {
console.log("notFine", this.popUpContainerDisplay);
this.newOpacity = parseInt(this.popUpContainerDisplay.style.opacity) - .01;
this.popUpContainerDisplay.style.opacity = String(this.newOpacity);
if (this.newOpacity <= 0)
{
this.popUpContainerDisplay.style.display = "none";
this.popUpContainerDisplay.style.opacity = "0";
}
else
{
requestAnimationFrame(this.fade);
}
}
constructor(private biddingService: BiddingService) {
biddingService.bids.subscribe(bid => {
if(bid.bidderArray){
this.bidderArray = bid.bidderArray; //.join('');
this.highestBid = bid.bid;
this.popUpContainerDisplay.style.display = bid.popUpContainerDisplay;
this.popUpContainerDisplay.style.opacity = bid.popUpContainerOpacity;
this.popUpAcceptContainerDisplay = bid.popUpAcceptContainerDisplay;
this.popUpDeclineContainerDisplay = bid.popUpDeclineContainerDisplay;
this.popUpWarningContainerDisplay = bid.popUpWarningContainerDisplay;
this.arrayReset = bid.resetArrayBoolean;
this.popUpFadeOut();
}
});
}
ngOnInit() and popUpFadeOut() log the element in the console, but fade() logs 'undefined'. Why is the element suddenly undefined?