我是角度js和打字稿的新手。我开始遵循文档中的angular2 英雄教程。但是我在教程的最后一节中遇到了一个错误,即 HTTP ,链接如下:
https://angular.io/docs/ts/latest/tutorial/toh-pt6.html
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import {AppRoutingModule} from './app-routing.module'
// Imports for loading & configuring the in-memory web api
import { InMemoryWebApiModule } from 'angular2-in-memory-web-api';
import { InMemoryDataService } from './apis/in-memory-data.service';
import { HeroesComponent } from './heroes/heroes.component';
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
import { AppmainComponent } from './appmain/appmain.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import {HeroService} from "./hero.service";
@NgModule({
declarations: [
HeroesComponent,
HeroDetailComponent,
AppmainComponent,
DashboardComponent
],
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
HttpModule,
InMemoryWebApiModule.forRoot(InMemoryDataService)
],
providers: [HeroService],
bootstrap: [AppmainComponent]
})
export class AppModule { }
内存数据-service.ts
import { InMemoryDbService } from 'angular2-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
let heroes = [
{id: 11, name: 'Mr. Nice'},
{id: 12, name: 'Narco'},
{id: 13, name: 'Bombasto'},
{id: 14, name: 'Celeritas'},
{id: 15, name: 'Magneta'},
{id: 16, name: 'RubberMan'},
{id: 17, name: 'Dynama'},
{id: 18, name: 'Dr IQ'},
{id: 19, name: 'Magma'},
{id: 20, name: 'Tornado'}
];
return {heroes};
}
}
我在终端收到的错误如下:
ERROR in Error encountered resolving symbol values statically. Calling function 'InMemoryWebApiModule', function calls are not supported.
Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /home/jainam/Projects/WebstormProjects/angularheroes/src/app/app.module.ts, resolving symbol AppModule in /home/jainam/Projects/WebstormProjects/angularheroes/src/app/app.module.ts
答案 0 :(得分:0)
尝试使用angular-in-memory-web-api
代替angular2-in-memory-web-api
。它为我解决了这个问题。
答案 1 :(得分:-1)
"angular-in-memory-web-api": "~0.3.0"