【问题标题】:Angular2 - Error encountered resolving symbol values statically. Calling function 'InMemoryWebApiModule', function calls are not supported.Angular2 - 静态解析符号值时遇到错误。调用函数“InMemoryWebApiModule”,不支持函数调用。
【发布时间】: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


    【解决方案1】:

    尝试使用angular-in-memory-web-api 而不是angular2-in-memory-web-api。它为我解决了这个问题。

    【讨论】:

    • 我也试过了,没有解决问题。你在 package.json 中使用的是什么版本的内存 api?
    • @Jainam/@Chris - 你们找到解决方案了吗?
    • @ThoughtfulMonkey,我已经放弃了,之后直接通过 HttpClient 进行 JSON 解析。好久没查文档了。 angular.io/guide/http
    【解决方案2】:
    "angular-in-memory-web-api": "~0.3.0"
    

    【讨论】:

    • 这与之前的答案有什么不同,请详细说明。
    猜你喜欢
    • 2017-07-06
    • 1970-01-01
    • 2017-07-28
    • 2018-03-04
    • 1970-01-01
    • 2017-10-24
    • 2017-03-30
    • 2017-06-08
    • 1970-01-01
    相关资源
    最近更新 更多