Type 'this' is not assignable to type 'Window'

Hello, I need to use the “self = this” trick in the app.component.ts file but it’s giving me a wierd error and I cannot find a solution in Google.

BTW: If I save the file while the android simulator is opened, it “rebuild” and the error disappear. It appears everytime that I use the “ionic cordova run android”:

https://i.imgur.com/l9UHNOv.jpg

I even tried a clean code like:

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen){
      self = this;
      ...
}

Any idea? I need it because I want to have the firebase.auth() listener in the app.component.ts:


 constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
	  
		self = this;

		platform.ready().then(() => {
	  
			//add listener
			firebase.auth().onAuthStateChanged(function(user) {
				if (user) {
					console.log('IS SIGNED IN -> Home page');
					self.rootPage = HomePage;
				} else {
					console.log('IS SIGNED OUT -> Login page');
					self.rootPage = LoginPage;
				}
			});

Any idea?

Fixed changing “self = this;” => “let self = this;” :man_facepalming:

This is bad style. It’s much cleaner if you subscribe to an Observable, either through angularfireauth or the Firebase SDK.

1 Like

I need to learn about Observables, never used it :confused:

Thank you, i’m gonna read about it ^^