Importing Providers (Services, Class, Pipes) RC.0

I’m trying to update an existent project to ionic to 2.0.0-rc.0 so I followed step by step the changelog (https://github.com/driftyco/ionic/blob/master/CHANGELOG.md#steps-to-upgrade-to-rc0), however I’m facing an issue.

I just removed all providers, directives and imports from my pages, and I put everything on app.module, as the following:

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { MyApp } from './app.component';

import { PresentationPage } from '../pages/presentation/presentation';
import { HomePage } from '../pages/home/home';
import { Service1 } from '../services/service1.service';
import { Pipe1 } from '../pipes/pipe1.pipe';
import { Class1 } from '../classes/class1';

@NgModule({
	declarations: [
		MyApp,
		PresentationPage,
            HomePage
	],
	imports: [
		IonicModule.forRoot(MyApp)
	],
	bootstrap: [IonicApp],
	entryComponents: [
		MyApp,
		PresentationPage,
		HomePage
	],
	providers: [
		Storage,
		Service1,
		Pipe1,
		Class1
	]
})
export class AppModule {}

And in my component:

@Component({
	selector: 'page-home',
	templateUrl: 'home.html'
})
export class HomePage {

	constructor(public navCtrl: NavController, public service1: Service1) {
        ...
	}
}

After put it in providers, do I have to do something to make it work in my components?

I’m getting the following error:

error TS2304: Cannot find name 'Service1'.
error TS4063: Parameter 'service1' of constructor from exported class has or is using private name 'Service1'.

Your system information:

Cordova CLI: 6.3.1
Gulp version: CLI version 3.9.1
Gulp local:
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
OS: Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS
Node Version: v6.3.1

Thanks.

1 Like

Same here. If i remove the imports, i get this.

Same here.

Anyone resolved this issue?

I think you still need to have the import in your component?

3 Likes

It works if you keep service imports in components. Documentation error?

Yes, I think the docs are in error. I was on the Angular 2 JumpStart workshop on Monday (prior to AngularConnect) and I’m pretty sure we imported the services in our components as well as placing them in the module file.

see here