我是新來的角js和打字稿。我開始按照該文件中的英雄的angular2 教程。但我在教程的最後一節,即HTTP跑進一個錯誤,鏈接如下所述:Angular2 - 遇到靜態解析符號值時出錯。調用函數'InMemoryWebApiModule',不支持函數調用。
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
我試過,還有,它並沒有解決這個問題。你在package.json中使用了什麼版本的內存api? –
@ Jainam/@ Chris - 你們有沒有找到解決辦法? –
@ThoughtfulMonkey,我已經放棄了,之後直接通過HttpClient進行JSON解析。很長一段時間沒有檢查文檔。 https://angular.io/guide/http –