@plx49638

Почему не работает ngxcookieservicessr?

Все делал по инструкции https://www.npmjs.com/package/ngx-cookie-service-ssr

1) Установил npm install ngx-cookie-service-ssr --save

2) в файле server.ts заменил строки

// All regular routes use the Universal engine
  server.get('*', (req, res) => {
    res.render(indexHtml, {
      req,
      providers: [
        { provide: APP_BASE_HREF, useValue: req.baseUrl },
        { provide: 'REQUEST', useValue: req },
        { provide: 'RESPONSE', useValue: res },
      ],
    });
  });

  return server;
}


3) в файле app.component.ts прописал

import { Component } from '@angular/core';
import { AutorizationService } from './components/authorization/autorization.service';
import { CategoryDataService } from './services/category_data.service';
import { SsrCookieService } from 'ngx-cookie-service-ssr';
 
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.sass'],
  providers: [CategoryDataService, AutorizationService, SsrCookieService],
})
export class AppComponent {
  
  constructor(public CategoryDataService: CategoryDataService, public AutorizationService: AutorizationService, private SsrCookieService: SsrCookieService ){
      this.SsrCookieService.set('Test', 'Hello World');
    //  this.cookieValue = this.cookieService.get('Test');
  }
  ngOnInit(){
  }
}


4) но все равно получаю ошибку от сервера.
Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with `EnvironmentInjector#runInContext`. Find more at https://angular.io/errors/NG0203
    at injectInjectorOnly (D:\project\frontend\dist\server\vendor.js:192077:11)
    at Module.ɵɵinject (D:\project\frontend\dist\server\vendor.js:192085:59)
    at Object.SsrCookieService_Factory [as factory] (D:\project\frontend\dist\server\vendor.js:218759:92)
    at R3Injector.hydrate (D:\project\frontend\dist\server\vendor.js:143321:29)
    at R3Injector.get (D:\project\frontend\dist\server\vendor.js:143222:23)
    at ChainedInjector.get (D:\project\frontend\dist\server\vendor.js:147235:32)
    at lookupTokenUsingModuleInjector (D:\project\frontend\dist\server\vendor.js:138632:31)
    at getOrCreateInjectable (D:\project\frontend\dist\server\vendor.js:138675:10)
    at Module.ɵɵdirectiveInject (D:\project\frontend\dist\server\vendor.js:145268:10)
    at NodeInjectorFactory.AppComponent_Factory [as factory] (D:\project\frontend\dist\server\main.js:106:406)


Или подскажите пожалуйста как вы работает с куками в Ангуляр Юниверсал
  • Вопрос задан
  • 80 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы