Angular 2 个本地存储 - "has no exported member" 编译错误

Angular 2 local storage - "has no exported member" compilation errors

在此先感谢您的帮助。我正在尝试使用 typescript 在 Angular 2 中获取本地存储访问权限。我正在使用 npm 包 angular2-localstorage。我有 angular.io "Tour of Heroes" 工作(没有太多样式)。我按照 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" 的本地存储而添加的每一行都有注释。如果您注释掉这三行,编译和运行时都可以正常工作。

此时只想能够编译成功。谢谢。

注意:这是我关于堆栈的第一个问题。过去我在这里找到了很多答案,并且我已经尽力按照约定提出这个问题。欢迎任何关于我在提问时应该做些什么的富有成效的反馈。

Angular2-LocalStorage 不再维护,您必须使用另一个库,直到这个库获得活跃的维护者。我推荐 Angular2 Cool Storage

将 "LocalStorageEmitter.ts" 中的这一行替换为 node_modeule "angular2-localstorage"

import {Type} from "@angular/core/src/facade/lang";
import {provide} from "@angular/core/src/di";
import {ComponentRef} from "@angular/core";

export function LocalStorageSubscriber(appPromise: Promise<ComponentRef<any>>) {
    appPromise.then((bla) => {
        bla.injector.get(<Type>LocalStorageService);
    });
}

有了这个。

import {Type} from "@angular/core/src/type";
import {Provider} from "@angular/core/src/di";
import {ComponentRef} from "@angular/core";

export function LocalStorageSubscriber(appPromise: Promise<ComponentRef<any>>) {
    appPromise.then((bla) => {
        bla.injector.get(<Type<any>>LocalStorageService);
    });
}

这对我有用...

更多详情=> https://github.com/marcj/angular2-localstorage/issues/66