Whenever I try to set a simple boolean variable to show/hide a div from another component, the ngIf directive doesn't seem to recognize it.
In my messages-refresh.component.html file:
<div class="divOpacity" *ngIf="show">
<div class="boxMessageModal">
<p>New data has been found for this page, click Ok to refresh!</p>
<button class="btnOktoReload" (click)="reloadPage()">Ok</button>
</div>
In my messages-refresh.component.ts file:
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
@Component({
selector: 'app-messages-refresh',
templateUrl: './messages-refresh.component.html',
styleUrls: ['./messages-refresh.component.css']
})
export class MessagesRefreshComponent implements OnInit {
constructor(private location:Location) { }
reloadPage(){
location.reload(true)
}
show:boolean = false
showDivOpacity(){
this.show = true
}
ngOnInit() {
}
}
To trigger the showDivOpacity method from another component, use
this.messagesRefreshComponent.showDivOpacity()