I have an Angular 4 app with server side rendering. On server side I have such code:
const res: express.Response = this.injector.get('RESPONSE');
res.cookie('Name', 'Value');
So, how in the component can I access this cookies? I inject Express RESPONSE in my component, but there are no cookies.
@Component({
selector: 'app-my',
templateUrl: './my.component.html',
styleUrls: ['./my.component.scss']
})
export class MyComponent implements OnInit {
constructor(@Inject(PLATFORM_ID) private platformId: Object, private injector: Injector) {
}
ngOnInit() {
if (isPlatformServer(this.platformId)) {
let CircularJSON = require('circular-json');
let res: express.Response = this.injector.get('RESPONSE');
console.log("RESPONSE = " + CircularJSON.stringify(res));
}
}
}
The problem is to get cookie on server side, before they will be set in browser.
您是否尝试过使用此ngx-cookie-service库访问cookie?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.