The pipe 'translate' could not be found , angular2 component testing

后端 未结 2 692
长情又很酷
长情又很酷 2021-01-07 23:13

I am working on component testing with angular2. in my html template i use the translate pipe. This is the code of the test :

import { ComponentFixture,          


        
2条回答
  •  长发绾君心
    2021-01-07 23:40

    With latest Angular 4 compatible ngx-translate you need to implement this directly into the component you want to test:

    import {TranslateHttpLoader} from "@ngx-translate/http-loader";
    import {Http, HttpModule} from "@angular/http";
    import {
        MissingTranslationHandler,
        TranslateLoader,
        TranslateModule,
        TranslateService
    } from "@ngx-translate/core";
    
    ...
    
    export function HttpLoaderFactory(http: Http) {
        return new TranslateHttpLoader(http, "./assets/i18n/", ".json");
    }
    
       ...
    
       imports: [
                    TranslateModule.forRoot({
                        loader: {
                            provide: TranslateLoader,
                            useFactory: HttpLoaderFactory,
                            deps: [Http]
                        }
                    })
                ],
       ...
    
       providers: [
                    TranslateService
       ...
    

提交回复
热议问题