AngularM
AngularM

Reputation: 16648

In angular2 does anyone know how to get angular2-google-maps working or know a similar node module

In angular2 does anyone know how to get angular2-google-maps working or know a similar node module.

This is my current module:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { FormsModule} from '@angular/forms';
import { AgmCoreModule } from 'angular2-google-maps/core';

import { SearchJobsComponent } from './searchJobs.component';


@NgModule({
  imports: [CommonModule, RouterModule, FormsModule, AgmCoreModule],
  declarations: [SearchJobsComponent],
  exports: [SearchJobsComponent],
  providers: []
})
export class SearchJobsModule { }

This is the error I get:

caused by: No provider for MapsAPILoader! No provider for MapsAPILoader! at NoProviderError.BaseError [as constructor] (core.umd.js:1104) at NoProviderError.AbstractProviderError [as constructor]

Upvotes: 0

Views: 1608

Answers (2)

Amit
Amit

Reputation: 4353

Like PerfectPixel said, you need to import AgmCoreModule with the .forRoot() call so it imports all the relevant providers as well (like MapsAPILoader for example).

Note that you need to do this once in your root module, and then import AgmCoreModule like you already are in each module that needs its components.

Upvotes: 1

PerfectPixel
PerfectPixel

Reputation: 1968

You are missing the .forRoot() call in your NgModule decorator:

@NgModule({
  imports: [CommonModule, RouterModule, FormsModule, AgmCoreModule.forRoot()],
  declarations: [SearchJobsComponent],
  exports: [SearchJobsComponent],
  providers: []
})

Be sure to checkout the setup guide here.

Upvotes: 2

Related Questions