/**
  * Helper methods to add ComponentClass(like modal backdrop) with options
  * of type ComponentOptionsClass to element next to application root
  * or next to provided instance of view container
  * @param ComponentClass - @Component class
  * @param ComponentOptionsClass - options class
  * @param options - instance of options
  * @param contextInjector - injector to resolve root view container (any injector except root injector will fit)
  * @returns {ComponentRef<T>} - returns ComponentRef<T>
  */
 public appendNextToRoot<T>(ComponentClass:Type<T>,
                            ComponentOptionsClass:any,
                            options:any,
                            contextInjector:Injector):ComponentRef<T> {
   let location = this.getRootViewContainerRef(contextInjector);
   let providers = ReflectiveInjector.resolve([
     {provide: ComponentOptionsClass, useValue: options}
   ]);
   return this.appendNextToLocation(ComponentClass, location, providers);
 }
Example #2
0
  beforeEach(function() {
    routeSet$ = new Subject<Match>();
    spyOn(router, 'replace');
    spyOn(observer, 'next');
    const injector = ReflectiveInjector.resolveAndCreate([
      provide(Router, { useValue: router })
    ]);

    redirect = injector.resolveAndInstantiate(RedirectHook);
  });
Example #3
0
  beforeEach(function() {
    routerInstruction$ = new Subject<Match>();
    const injector = ReflectiveInjector.resolveAndCreate([
      PARAMS_PROVIDERS,
      provide(RouterInstruction, { useValue: routerInstruction$ })
    ]);

    routeParams$ = injector.get(RouteParams);
    queryParams$ = injector.get(QueryParams);
  });
Example #4
0
    beforeEach(function () {
        const injector = ReflectiveInjector.resolveAndCreate([
            ShopEffects,
            MOCK_EFFECTS_PROVIDERS,
            // Mock out other dependencies (like Http) here
        ]);

        shop = injector.get(ShopEffects);
        updates$ = injector.get(MockStateUpdates);
    });
Example #5
0
 useInjectors(): void {
     let injector: any = ReflectiveInjector.resolveAndCreate([
         ViewPortService,
         provide('OtherSizeService', {useFactory: (viewport: any) => {
             return viewport.determineService();
         }, deps: [ViewPortService]})
     ]);
     let sizeService: any = injector.get('OtherSizeService');
     sizeService.run();
 }
Example #6
0
 it('should infer type', () => {
   // #docregion InjectionToken
   const BASE_URL = new InjectionToken<string>('BaseUrl');
   const injector =
       ReflectiveInjector.resolveAndCreate([{provide: BASE_URL, useValue: 'http://localhost'}]);
   const url = injector.get(BASE_URL);
   // here `url` is inferred to be `string` because `BASE_URL` is `InjectionToken<string>`.
   expect(url).toBe('http://localhost');
   // #enddocregion
 });
Example #7
0
 beforeEach(() => {
   var injector = ReflectiveInjector.resolveAndCreate(
       [{provide: ResponseOptions, useClass: BaseResponseOptions}, MockBackend]);
   backend = injector.get(MockBackend);
   var base = new BaseRequestOptions();
   sampleRequest1 = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));
   sampleResponse1 = new Response(new ResponseOptions({body: 'response1'}));
   sampleRequest2 = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));
   sampleResponse2 = new Response(new ResponseOptions({body: 'response2'}));
 });
 beforeEach(() => {
   let injector = ReflectiveInjector.resolveAndCreate([
     ROUTER_FAKE_PROVIDERS,
     // Angulartics2 relies on router for virtual page view tracking
     Angulartics2, Angulartics2Segment, AnalyticsService
   ]);
   analyticsService = injector.get(AnalyticsService);
   analyticsService.devMode(false);
   segment = injector.get(Angulartics2Segment);
 });
  beforeEach(() => {
    onerrorSpy = jasmine.createSpy('onerror');
    superHandler = spyOn(ErrorHandler.prototype, 'handleError');

    const injector = ReflectiveInjector.resolveAndCreate([
      { provide: ErrorHandler, useClass: ReportingErrorHandler },
      { provide: WindowToken, useFactory: () => ({ onerror: onerrorSpy }) }
    ]);
    handler = injector.get(ErrorHandler);
  });
function createInjector(initialUrl: string) {
  return ReflectiveInjector.resolveAndCreate([
      DocumentService,
      { provide: LocationService, useFactory: () => new MockLocationService(initialUrl) },
      { provide: ConnectionBackend, useClass: MockBackend },
      { provide: RequestOptions, useClass: BaseRequestOptions },
      { provide: Logger, useClass: MockLogger },
      Http,
  ]);
}