1

I'm following this tutorial https://www.pointblankdevelopment.com.au/blog/113/aspnet-core-20-angular-24-user-registration-and-login-tutorial-example For user registrations and login

But when I run application I'm getting next error: enter image description here

I read on few articles about this but nothing helped me. Here is my code on git:Code on GIT Can anyone help me to understand where I made mistake and how can fix it ?

Thanks and Regards,

Danijel Boksan
  • 779
  • 1
  • 13
  • 30
  • i think u are facing this issue in universal ( server side rendering ) only and not in browser, right ? – Dhyey Nov 09 '17 at 08:09
  • I'm running directly from Visual Studio, it is not deployed to the server. So, not sure. How can I check this and let you know correct answer ? – Danijel Boksan Nov 09 '17 at 08:13
  • Aren't you compiling and running it in browser ? Line 10 in [this file](https://github.com/danijel88/AngularPDM/blob/master/AngularPDM/ClientApp/app/components/_guards/auth.guard.ts) is causing the error. – Dhyey Nov 09 '17 at 08:15
  • You should checkout [this answer](https://stackoverflow.com/questions/39085632/localstorage-is-not-defined-angular-universal) – Dhyey Nov 09 '17 at 08:16
  • Yes, I'm compiling and running it in browser. I will try your suggested answer and let it you know. – Danijel Boksan Nov 09 '17 at 08:18
  • That is not helping me... – Danijel Boksan Nov 09 '17 at 08:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/158587/discussion-between-danijel-boksan-and-dhyey). – Danijel Boksan Nov 09 '17 at 08:36
  • https://stackoverflow.com/questions/39085632/localstorage-is-not-defined-angular-universal – AT82 Nov 09 '17 at 15:50

1 Answers1

0

You need use "isPlatformBrowser"

Import:

import { isPlatformServer, isPlatformBrowser } from '@angular/common';

and declare in the constructor:

constructor(private _http: Http, @Inject(PLATFORM_ID) private platformId: Object)...

use:

public setValue(value){

    if (isPlatformBrowser(this.platformId)) {
            localStorage.setItem('varX', value);
            ........
        }
}