【发布时间】:2017-06-07 06:25:51
【问题描述】:
我是 Angular js 和打字稿的新手。我首先按照文档中的 angular2 Tutorials of Heroes 进行操作。但是我在教程的最后一部分遇到了一个错误,即 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 { }
in-memory-data-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
【问题讨论】:
标签: angular angular2-routing angular2-http