I am currently developing a demo application using Angular 2, and I have encountered a problem. I need to utilize a global variable or object across the entire application similar to $rootScope
in Angular. Could you please provide me with some suggestions on how I can achieve this? Right now, I am using EventEmitter
.
app.component.ts:
<a routerLink="/admin" routerLinkActive="active" style="float:right;"
*ngIf="currentUrl != '/admin'" (adminUrl)="setUrl($event)" >Admin-{{currentUrl}}</a>
`@Output() adminUrl:String;`
heroes.component.ts:
@Output() adminUrl = new EventEmitter();
this.adminUrl.emit(this.router.location.path());
The above code snippet is just a part of the overall implementation to illustrate my approach towards achieving the desired functionality.