2017-01-30 71 views

回答

1

鏈接:https://github.com/2muchcoffeecom/ng2-restangular/blob/master/demo/mock-data/mock-providers.ts

import {BaseRequestOptions, Http} from "@angular/http"; 
import {MockBackend} from "@angular/http/testing"; 
import {RestangularHttp} from "../../src/ng2-restangular-http"; 

export const MockProviders = [ 
    BaseRequestOptions, 
    MockBackend, 
    { 
    provide: RestangularHttp, 
    useFactory: (http: Http) => { 
     return new RestangularHttp(http); 
    }, 
    deps: [Http] 
    }, 
    { 
    provide: Http, 
    useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => { 
     return new Http(backendInstance, defaultOptions); 
    }, 
    deps: [MockBackend, BaseRequestOptions] 
    }, 
]; 
+0

雖然這可以回答這個問題,考慮增加一個簡短的說明 –

+0

謝謝Tonyo!進一步調查的好點 –