i have a Authentication Service in Angular, which should handle log in and out for me. So this is an @Injectable({providedIn: 'root'}).
In this service i want to use the ngx-cookie-service (https://www.npmjs.com/package/ngx-cookie-service).
My system is running on angular 14.
When i try to run it, i get the error ERROR Error: NG0203: inject() must be called from an injection context (a constructor, a factory function or a field initializer). Find more at https://angular.io/errors/NG0203
My AuthenticationService:
@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
readonly url: string = 'http://localhost:4200/api/';
statusSubject: ReplaySubject<boolean> = new ReplaySubject<boolean>(1);
userType: UserTypes = UserTypes.User;
cookieService: CookieService | undefined;
constructor(
private httpClient: HttpClient,
private backendService: BackendService,
private addressStore: AddressStore,
private orderStore: OrderStore,
private shoppingCartStore: ShoppingCartStore,
private userStore: UserStore,
private wishlistStore: WishlistStore
) {
this.cookieService = inject(CookieService);
if (this.cookieService.get("sessionKey") != null) {
this.statusSubject.next(true);
} else {
this.statusSubject.next(false);
}
}
login(){...}
logout(){...}
}
How can I use the CookieService in mine?
Thanks for your help!