代码之家  ›  专栏  ›  技术社区  ›  Jonathan Reyes

DI不在Safari上工作

  •  1
  • Jonathan Reyes  · 技术社区  · 8 年前

    我找到了一些 fantastic links Angular2中的DI解释,但我仍然无法在Safari上使用它。在下面的代码中,它可以在Firefox和Chrome中工作,但我仍然得到一个 Can't resolve all parameters for ApiService: (Http, ?). 在Safari。我错过了什么吗?

    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
      ) {}
    }
    

    据我所知,是否有一个已知的跨浏览器兼容性问题我遗漏了?或者可能是专门为狩猎而设的聚合填料?

    • 我已设置@NgModules以包括 HttpModule

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

    1 回复  |  直到 8 年前
        1
  •  1
  •   Community Biraj Zalavadia    7 年前

    @GnterZchbauer 100%正确,因为问题是提供者的格式。@NgModule中没有provide(),现在:

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

    Angular2 - How to inject window into an angular2 service