0

I'm trying to add google map capabilities to one of my app page and I'm following this tutorial : http://www.joshmorony.com/creating-an-advanced-google-maps-component-in-ionic-2/

At stage 1. I need to update my app.module.ts to include the ConnectivityService in the provider list.

The page provides an example, but in my application I already have two providers which leads me to have the following app.module.ts before the addition:

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { Page1 } from '../pages/page1/page1';
import { Page2 } from '../pages/page2/page2';
import { MapPage } from '../pages/map/map';

@NgModule({
  declarations: [
    MyApp,
    Page1,
    Page2,
    MapPage
  ],
  imports: [
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    Page1,
    Page2,
    MapPage
  ],
  providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}

Then, to adapt to the tutorial I've added at the beginning

import { ConnectivityService } from '../providers/connectivity-service';

And changed my provider to :

providers: [{provide: ErrorHandler, useClass: IonicErrorHandler, ConnectivityService}]

but I get an error:

Argument of type '{ declarations: (typeof Page1 | typeof Page2 | typeof MyApp)[]; imports: ModuleWithProviders[]; b...' is not assignable to parameter of type 'NgModule'. Types of property 'providers' are incompatible. Type '{ provide: typeof ErrorHandler; useClass: typeof IonicErrorHandler; ConnectivityService: typeof C...' is not assignable to type 'Provider[]'. Type '{ provide: typeof ErrorHandler; useClass: typeof IonicErrorHandler; ConnectivityService: typeof C...' is not assignable to type 'Provider'. Object literal may only specify known properties, and 'ConnectivityService' does not exist in type 'Provider'.

An I have the same kind of error if I change to :

  providers: [{provide: ErrorHandler, useClass: IonicErrorHandler,  connectivityService:ConnectivityService}]

What is the right way for me to do it?

Thanks!

1 답변


0

Ok I found it, I should have written :

  providers: [ConnectivityService, {provide: ErrorHandler, useClass: IonicErrorHandler}]

But I don't know why that works and what should be in {} and what should be out

Related

Latest