没有ConnectionBackend for ionic 2的提供者 [英] No provider for ConnectionBackend for ionic 2

查看:97
本文介绍了没有ConnectionBackend for ionic 2的提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯使用离子2,我创建了一个简单的服务

im using ionic 2 and i create a simple service

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';

@Injectable()
export class EliteApi {

  private baseUrl="https://myurl.com";
    constructor(private http:Http) { }

    getTournaments(){
      return new Promise(resolve =>{
        this.http.get(this.baseUrl + 'tournaments.json').subscribe(res => resolve(res.json()));

      });
    }
}

然后我在app.component.ts上导入它这是注册服务

then i import it on app.component.ts like this to register the service

import { EliteApi } from './shared/shared';
import {Http} from "@angular/http";

@Component({
  templateUrl: 'app.html',
  providers: [EliteApi,Http]
})

在我的页面上我导入服务

after that on my page i import the service

import { EliteApi } from '../../app/shared/shared';

并且在加载的事件上我写了这个来获取json数据

and on the event loaded i wrote this to get the json data

  ionViewLoaded(){
    this.eliteApi.getTournaments().then(data => this.tournaments = data);
  }

它给我例外说
没有ConnectionBackend的提供者!

it gives me exception says No provider for ConnectionBackend!

我试过类似这里的一些问题说将服务放在供应商上这个

i tried as some question similar here says put the service on providers as this

@NgModule({
提供者:[EliteApi

@NgModule({ providers: [ EliteApi

但同样的错误

推荐答案

您是否在 App 模块中导入 HttpModule

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

@NgModule({
   imports: [HttpModule]
})

这篇关于没有ConnectionBackend for ionic 2的提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆