![](/img/trans.png)
[英]'Error: Uncaught (in promise): No provider for Jsonp' (HTML / Javascript / Typescript / Angular2)
[英]angular 4 Error: Uncaught (in promise): Error: No provider for ConnectionBackend! while injecting Jsonp
當我嘗試注入Jsonp時,我看到此錯誤
異常:調用Node模塊失敗,並顯示以下錯誤:錯誤:未捕獲(承諾):錯誤:沒有ConnectionBackend的提供程序! 錯誤:沒有ConnectionBackend的提供者! 錯誤(本機)
我的home.component.ts文件
import { NgModule, Component, Injectable } from '@angular/core';
import { HttpModule, JsonpModule, Jsonp, Response, URLSearchParams, Headers, RequestOptions } from '@angular/http';
@Component({
selector: 'home',
templateUrl: './home.component.html',
providers: [HttpModule, JsonpModule, Jsonp]
})
@Injectable()
export class HomeComponent {
public jsonp: Jsonp;
constructor(jsonp: Jsonp) {
this.jsonp = jsonp;
}
請幫助我解決此問題。
providers
數組只能有Injectable
而不是modules
providers: [HttpModule, JsonpModule, Jsonp]
應該
providers: [Jsonp]
還要確保在AppModule的imports
NgModule中應該包含HttpModule, JsonpModule
AppModule
您JsonpModule
在JsonpModule
中錯過import JsonpModule
,在接下來的app.module.ts
行中,我向您展示了應該在哪里導入JsonpModule
。
app.module.ts
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { JsonpModule } from '@angular/http'; import { HttpModule } from '@angular/http'; import { HomeComponent } from './yourComponentFolder/home.component' @NgModule({ declarations: [ AppComponent, HomeComponent, ], imports: [ BrowserModule, HttpModule, JsonpModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.