evertonrobertoauler / cli-universal-demo

80 stars 18 forks source link

Is there any way to use cookie values in the server? #21

Closed adebree closed 7 years ago

adebree commented 7 years ago

Thanks for your example repo! Really helpful. I do encounter a challenge with reading cookie data. How to get the cookie value from the request? renderModuleFactory or Express itself doesn't seem to inject it.

TroodoNmike commented 7 years ago

I use ngx-cookie package and whenever I need to use cookie data I have to use isBrowser property. Here is an example:

import { isPlatformBrowser } from '@angular/common';
import { PLATFORM_ID } from '@angular/core';
public isBrowser: boolean = isPlatformBrowser(this.platformId);

// component constructor
constructor(@Inject(PLATFORM_ID) private platformId, private cookieService: CookieService) {}

    if (this.isBrowser) {
        let name = cookieService.get('name');
    }
evertonrobertoauler commented 7 years ago

You can use this library, https://www.npmjs.com/package/universal-cookie