2017-01-22 17 views
1

Ich bin neu in eckigen js und Typoskript. Ich fing an, indem ich die angular2 Tutorials von Heroes in der Dokumentation folgte. Aber ich in einen Fehler lief im letzten Abschnitt des Tutorials dh HTTP, Link unten erwähnt:Angular2 - Fehler beim statischen Auflösen der Symbolwerte. Beim Aufruf der Funktion 'InMemoryWebApiModule' werden Funktionsaufrufe nicht unterstützt.

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-Daten -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}; 
    } 
} 

Der Fehler, den ich im Terminal ist wie folgt:

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 

Antwort

0

Versuchen angular-in-memory-web-api statt angular2-in-memory-web-api verwenden. Es hat das Problem für mich gelöst.

+0

Ich versuchte das auch, es behob das Problem nicht. Welche Version von In-Memory-API verwendest du in deinem package.json? –

+0

@ Jainam/@ Chris - Hast du irgendeine Lösung gefunden? –

+0

@ThoughtfulMonkey, ich hatte das aufgegeben und JSON danach direkt über HttpClient geparst. Habe die Dokumente lange nicht überprüft. https://angular.io/guide/http –

-1
"angular-in-memory-web-api": "~0.3.0" 
+2

Wie ist das anders als vorherige Antwort, bitte erarbeiten. – mpaskov

Verwandte Themen