Unable to access the $ rootscope property declared in one controller in another in angular using typescript

I declared a custom rooting property in the ts file as shown below

module MyApp.Entity{

    export interface IRootScope extends ng.IRootScopeService {
        userData: any;
        clientData: any;
    }
} 

In one of my service files, I assigned a value

    export class Service1 {

            constructor(private apiService: MyApp.Common.Services.apiService, private notificationService: MyApp.Common.Services.notificationService,
                 private $base64: JQueryBase64Static, private $cookieStore: ng.cookies.ICookieStoreService, private $rootScope: MyApp.Entity.IRootScope) {
            }

    saveData(){
    this.$rootScope.clientData = clientData; // Data got assigned 


    }
}

Now in another Controller file, I tried to access this rootcope property

class controller2{
Clients: any;
constructor(private service1: MyApp.Service.Service1, private $rootScope: MyApp.Entity.IRootScope){
this.Clients = this.$rootScope.clientData; // clientData is Undefined i.e here //it is creating new rootscope again I guess ..so How to access a single global //rootscope
}
  }
-1
source share
1 answer

You are using this.$rootScope, which is another instance of $ rootScope, since it is defined only in your current area, if you delete this.it should work

0
source

All Articles