提前感谢您的帮助。我正在尝试使用打字稿在 Angular 2 中获得本地存储访问权限。我正在使用 npm 包 angular2-localstorage。我有 angular.io “英雄之旅” 工作(没有太多样式)。我按照https://www.npmjs.com/package/angular2-localstorage的说明进行操作。将建议的代码添加到我的 app.module.ts 文件后,我尝试使用 运行npm start
,并得到以下编译错误:
node_modules/angular2-localstorage/LocalStorageEmitter.ts(46,9): error TS2305: Module '"/Users/joshuaforman/Documents/CodeCraft/a2quickstart/a2-angular/node_modules/@angular/core/src/facade/lang"' has no exported member 'Type'.
node_modules/angular2-localstorage/LocalStorageEmitter.ts(47,9): error TS2305: Module '"/Users/joshuaforman/Documents/CodeCraft/a2quickstart/a2-angular/node_modules/@angular/core/src/di"' has no exported member 'provide'.
您可以在此处查看所有代码:https ://github.com/joshuaforman/angular2-quickstart
此外,这是完整的 app.module.ts 文件(我更改的唯一一个导致错误发生的文件):
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { HttpModule } from "@angular/http";
// added for LocalStorage
// followed instructions here: https://www.npmjs.com/package/angular2-localstorage
import { LocalStorageService, LocalStorageSubscriber } from "angular2-localstorage/LocalStorageEmitter";
// Imports for loading & configuring the in-memory web api
import { InMemoryWebApiModule } from "angular2-in-memory-web-api";
import { InMemoryDataService } from "./in-memory-data.service";
import { AppComponent } from "./app.component";
import { HeroDetailComponent } from "./hero-detail.component";
import { HeroesComponent } from "./heroes.component";
import { HeroService } from "./hero.service";
import { DashboardComponent } from "./dashboard.component";
import { routing } from "./app.routing";
@NgModule({
imports: [
BrowserModule,
HttpModule,
InMemoryWebApiModule.forRoot(InMemoryDataService),
FormsModule,
routing
],
declarations: [
AppComponent,
HeroesComponent,
HeroDetailComponent,
DashboardComponent
],
bootstrap: [ AppComponent ],
providers: [
HeroService,
LocalStorageService // added for Local Storage
]
})
export class AppModule {
// added for Local Storage
constructor(storageService: LocalStorageService) {}
}
我为实现包含文本“LocalStorage”的本地存储而添加的每一行都有注释。如果您注释掉这三行,编译和运行时就可以正常工作。
此时,我只想能够编译成功。谢谢。
注意:这是我在堆栈上的第一个问题。过去我在这里找到了很多答案,并且在提出这个问题时我已尽力遵循惯例。欢迎任何关于我在提问时应该做些什么的富有成效的反馈。