Not able to use provider in Ionic 2 (2.0.0-rc.4)


#1

Database provider

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class Database {

  constructor(public http: Http) {
    console.log('Hello Database Provider');
  }
}

app.component.ts

import { Database } from '../providers/database';

@Component({
  templateUrl: 'app.html',
  providers:[Database]
})
export class MyApp {
}

app.module.ts

import { Database } from '../providers/database';

@NgModule({
  declarations: [
    MyApp  ],
  imports: [
    IonicModule.forRoot(MyApp)  ],
  bootstrap: [IonicApp],
  entryComponents: [    MyApp   ],
  providers: [Database]
})

List.ts (page)

import { Database } from '../providers/database';

@Component({
  selector: 'page-list',
  templateUrl: 'list.html',
  providers: [Database]
})
export class ListPage {
   constructor(public navCtrl: NavController, public navParams: NavParams, public dataservice: Database) {
}

The error is can not find name Database

Kindly help me fix this error

I am using following version
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 0.0.47
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.9.2
Xcode version: Not installed


#2

Don’t put providers in the component, only the app module.


#3

Thank you. It worked