角度2中的模拟连接

时间:2017-04-21 18:23:21

标签: angular

我一直在关注jwt身份验证here

的教程

当我在app.module.ts的provider部分中包含MockConnection时,我收到此错误:

  

SyntaxError {__zone_symbol__error:错误:无法解析MockConnection的所有参数:(?)。       在SyntaxError.ZoneAwareError(http ......}

这是我完整的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 { DataTableModule } from '../../node_modules/primeng/components/datatable/datatable' ;
import { CalendarModule } from '../../node_modules/primeng/components/calendar/calendar' ;

// used to create fake backend
import { fakeBackendProvider } from './helpers/fake.backend';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { BaseRequestOptions } from '@angular/http';

import { AppComponent } from './app.component';
import { UpcomingManualDateComponent } from './components/opcon/upcoming-manual-date/upcoming-manual-date.component';
import { LogoComponent } from './components/logo/logo.component';
import { LoginComponent } from './components/login/login.component';
import { AppRoutingModule } from './app.routing' ;
// import { IdentityGuard } from './guards/identity.guard';
import { IdentityService } from './services/identity/identity.service';
//import { UserService } from './services/user/user.service';
import { HomeComponent } from './components/home/home.component';
import { PagenotfoundComponent } from './components/pagenotfound/pagenotfound.component';
import { RegisterComponent } from './components/register/register.component' ;

@NgModule({
  declarations: [
    AppComponent,
    UpcomingManualDateComponent,    
    LogoComponent, 
    LoginComponent, 
    HomeComponent,
    PagenotfoundComponent,
    RegisterComponent
  ],
  imports: [
    BrowserModule,
    DataTableModule , 
    CalendarModule ,
    FormsModule,
    HttpModule ,
    AppRoutingModule
  ],
  providers: [
//    IdentityGuard , 
    IdentityService , 
  //  UserService , 
    fakeBackendProvider , 
    MockBackend , 
    MockConnection , //<--CAUSES ERROR
    BaseRequestOptions
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
&#13;
&#13;
&#13;

显然,我对Angular2很新。有人可以向我解释这是如何导致错误的吗?

1 个答案:

答案 0 :(得分:0)

当您看到实现的app.module时,它在提供者列表中不包含MockConnection

@NgModule({
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        routing
    ],
    declarations: [
        AppComponent,
        LoginComponent,
        HomeComponent
    ],
    providers: [
        AuthGuard,
        AuthenticationService,
        UserService,

        // providers used to create fake backend
        fakeBackendProvider,
        MockBackend,
        BaseRequestOptions
    ],
    bootstrap: [AppComponent]
})

export class AppModule { }

See here