1

I have found some fantastic links for DI explanations in Angular2, but I am still unable to get it working on Safari. In the code below, it works in Firefox and Chrome, but I still get a Can't resolve all parameters for ApiService: (Http, ?). in Safari. Am I missing something?

import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Rx';

import { EmitterService } from '../services/emitter.service';

@Injectable()
export class ApiService {
  constructor (
    private http: Http,
    private window: Window
  ) {}
}

From what I can tell everything is there, is there a known cross-browser compatibility issue that I am missing? Or maybe a polyfill for safari specifically?

  • I have setup the @NgModules to include HttpModule as well.

import { HttpModule } from '@angular/http';

Jonathan Reyes
  • 1,387
  • 1
  • 10
  • 23
  • How do you provide dependencies? – Günter Zöchbauer Aug 21 '16 at 13:34
  • @GünterZöchbauer As of right now I have @NgModule({ imports: [ HttpModule, – Jonathan Reyes Aug 21 '16 at 14:29
  • 1
    The `Http` dependency import is not the problem. As you see in the error message, the 2nd parameter `Window` is the problem. See also http://stackoverflow.com/questions/34177221/angular2-how-to-inject-window-into-an-angular2-service especially the comment below http://stackoverflow.com/a/35003208/217408 – Günter Zöchbauer Aug 21 '16 at 14:30
  • Ah,I see-- I thought it stopped at the import it couldn't resolve... So we can't do this now with the @NgModules? providers: [ Title, provide(Window, { useValue: window }) ], – Jonathan Reyes Aug 21 '16 at 14:35
  • 1
    Did you try http://stackoverflow.com/a/38875374/217408 I don't have a Safari browser available to test it myself. – Günter Zöchbauer Aug 21 '16 at 14:39

1 Answers1

1

@GünterZöchbauer was 100% correct in that the issue was the formatting of the providers. It's not provide() in the @NgModule, its now:

@NgModule({
  providers: [
    Title,
    { provide: 'Window',  useValue: window }
  ],
  bootstrap: [ AppComponent ]
})

Angular2 - How to inject window into an angular2 service

Community
  • 1
  • 1
Jonathan Reyes
  • 1,387
  • 1
  • 10
  • 23