I am looking to develop a directive that allows me to utilize a template variable in order to access a global variable, much like $rootScope
in Angular.JS. The goal is to avoid having to inject a service into every component where I need access to the variable.
Here's an example:
@Directive({
selector: '[app]',
exportAs: 'app'
})
export class AppDirective {
isLoggedIn: boolean = false;
constructor() {
// Code to initialize 'this.ready' will go here...
}
}
The intention is to use the code above in my template as follows:
<div #app>
<div *ngIf="app.isLoggedIn">...</div>
</div>
Is it possible to achieve something like this?