Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用注入的angularjs服务测试角度管道_Angular_Angular Services_Angular Hybrid - Fatal编程技术网

无法使用注入的angularjs服务测试角度管道

无法使用注入的angularjs服务测试角度管道,angular,angular-services,angular-hybrid,Angular,Angular Services,Angular Hybrid,AngularJS服务: app.service('NameService', function() { this.name = function (name) { return "Hello " + name; } }); 角度升级: import { InjectionToken } from "@angular/core"; export const NameService = new InjectionToken<any&g

AngularJS服务:

app.service('NameService', function() {
  this.name = function (name) {
    return "Hello " + name;
  }
});
角度升级:

import { InjectionToken } from "@angular/core";
export const NameService = new InjectionToken<any>('NameService');

export function nameServiceFactory(i: any): any {
  return i.get('NameService');
}
export const nameServiceProvider = {
  provide: NameService,
  useFactory: nameServiceFactory,
  deps: ['$injector']
};
我在测试这根管子时遇到了问题

describe('NamePipe', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [],
      providers: [nameServiceProvider],
      declarations: [NamePipe]
    })
    .compileComponents();
  }));

  it('create an instance', () => {
    const service: any = TestBed.get(NameService);
    const pipe = new NamePipe(service);
    expect(pipe).toBeTruthy();
  });
});
这会引发以下错误:

NullInjectorError:没有$injector的提供程序

我在这里尝试过查看createAngularJSTestingModulecreateAngularTestingModule,但没有任何运气

一旦我将AngularJS模块拉入测试,我就会发现错误,即AngularJS模块中没有加载程序来处理.html文件类型

如何将升级的AngularJS服务注入角度测试组件

describe('NamePipe', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [],
      providers: [nameServiceProvider],
      declarations: [NamePipe]
    })
    .compileComponents();
  }));

  it('create an instance', () => {
    const service: any = TestBed.get(NameService);
    const pipe = new NamePipe(service);
    expect(pipe).toBeTruthy();
  });
});