I am creating a demo app in Angular 2 and I stuck in this app. I want to use a global variable/object throughout the app like $rootScope
in angular. Please suggest me what to do to achieve this?
Currently, 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 is not all code, this is for understanding that what I am doing to achieve for the same.