这可能是由于浏览器安全问题导致的。可以启用浏览器的Cookie和本地存储,并将其连接到Angular应用程序中。以下是一个示例,可在app.module.ts中添加:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
constructor() {
// 启用本地存储
localStorage.setItem('example', 'example-value');
// 启用cookie
document.cookie = 'example=example-cookie';
}
}
这应该在localhost:4200上启用Cookies和本地存储。如果仍然为空,请考虑检查浏览器的隐私设置。