Google Maps not displaying in nested Angular 2 component

After following the recommended steps to place Google map code in the Angular2 app.component, everything was working perfectly. However, I encountered an issue when trying to display the map in a shared nestable component called google-maps.component. The map simply refuses to show up.

Everything seems to be configured correctly:

A. Moving the code snippet(2) from the google-maps.component.html to the app.component.html displays the map properly

B. The text inside the h1 tag (from snippet 2 below) appears at the correct location on the rendered page where the google-maps component selector is placed

C. The console shows that the window object has a .google.map property

Q: How can I get the Google map to display correctly when used from the testable component?

Here's a breakdown of the code being used:

(1) google-maps.component.css

sebm-google-map-container{
  height: 300px;
}

(2) google-maps.component.html

<h1>GOOGLE MAPS COMPONENT START**********</h1>
<sebm-google-map [latitude]="50" [longitude]="50">
</sebm-google-map>
<h1>GOOGLE MAPS COMPONENT END**********</h1>

(3) google-maps.component.ts

import { Component } from '@angular/core';

@Component({
    selector: 'google-maps',
    templateUrl: './google-maps.component.html',
    styleUrls: ['./google-maps.component.css'],
})
export class GoogleMapsComponent {}

(4) app.module.ts

...
import { AgmCoreModule }    from 'angular2-google-maps/core';
import { GoogleMapsComponent }        from './shared/google-maps.component';
...
@NgModule({
    imports: [ AgmCoreModule.forRoot({ apiKey: '...' }),
        RouterModule.forRoot([  ...   ])     
    ],
    declarations: [ ..., AppComponent, GoogleMapsComponent ],
    bootstrap: [ AppComponent ]
})
export class AppModule  { }

Answer №1

Can you believe it? There was a missing ',' (comma) in the css selector

incorrect: sebm-google-map-container { ... }

correct format: .sebm-google-map-container { ... }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountered an Angular 4 issue - ERROR in main.ts file: Module not located - Error: Unable to resolve './$$_gendir/app/app.module.ngfactory'

While running the production build for Angular (ng build --prod), an error is encountered: ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Applications/MAMP/htdocs/bandpay/stg-b ...

Bringing in External Components/Functions using Webpack Module Federation

Currently, we are experimenting with the react webpack module federation for a proof of concept project. However, we have encountered an error when utilizing tsx files instead of js files as shown in the examples provided by the module federation team. We ...

Angular2 is designed to break down complex applications into smaller, more manageable parts

Need for a Solution Recently, I was given responsibility of overseeing a large, legacy web application at work that involves multiple scrum teams and development teams. One major issue we face with this application is that whenever one team makes updates ...

What is the proper way to refactor this TypeScript class?

Can you assist me in converting this class into TypeScript and explaining why it's not functioning? class Students { public name: string; public surname: string; public age: number; } constructor(name:string,surname:string,age:number) { ...

What is the reasoning behind referring to RxJS Subject as Multicast and Observable as Unicast?

I've been delving into RxJS for a while now and I'm struggling to grasp why we refer to RxJS Subject as Multicast and Observable as Unicast. I understand that Subject can emit data using next(), and like a regular Observable, we can subscribe to ...

Using Angular to subscribe to a BehabiourSubject within a service

Within the service itself, I am attempting to subscribe to the BehaviorSubject currentTheme. @Injectable({providedIn: 'root'}) export class ThemeService { currentTheme: BehaviorSubject<string>; constructor(@Inject(DOCUMENT) private docu ...

Using the Ajax method from a separate class in TypeScript: A step-by-step guide

Recently, I started learning about typescript and ajax. One of the challenges I encountered was while creating a method in typescript for making ajax calls that can be used across classes: myFunc(value: string): JQueryPromise<any> { var dfd = $. ...

Troubleshooting a Gulp.js issue during the execution of a "compile" task

Currently, I am utilizing gulp to streamline a typescript build system specifically designed for an Angular 2 frontend. However, I have encountered a problem with my "build" task that has been configured. Below is the exact task in question: gulp.task(&a ...

Storing images from Firebase Storage in the PWA app's cache for faster access

Currently, I have an Angular application with PWA functionality set up. In addition to caching assets/images, I am interested in caching images from Firebase Storage once they are loaded while online. The app utilizes Cloud Firestore with data persistence ...

Mastering Typescript lookup types - effectively limit the properties included in a merge operation with the Partial type

Exploring lookup types, I'm interested in creating a safe-merge utility function that can update an entity of type T with a subset of keys from another object. The objective is to leverage the TypeScript compiler to catch any misspelled properties or ...

Efficiently Combining Objects with Rxjs

I have a specific object structure that I am working with: const myObject = { info: [ { id: 'F', pronouns: 'hers' }, { id: 'M', pronouns: 'his'} ], items:[ { name: 'John', age: 35, ...

Adding an external JavaScript file to an Angular 5.0.0 project

Struggling to integrate hello.js into my Angular 5.0.2 project. See the CLI version below https://i.sstatic.net/RcGz5.jpg I have included the script file in angular-cli.json. "scripts": [ "./js/hello.js", "./js/hello.polyfill.js", ...

Tips on dynamically naming form controls based on user input

I am working on creating a JSON object using Angular 8 forms, where the control name will be defined by the user through a text input field. This control will contain formArrays of unit and price elements, allowing users to add as many unit-price combinati ...

When it comes to carousel dynamic items, I encounter an issue when using the splice function to remove an item

When using the splice function to delete an item (image), all the images are being deleted. When I delete an item, I want the carousel to show the remaining images instead of disappearing. <div id="carouselExampleControls" class="carousel slide" data ...

Is the new Angular 2 CLI tool incorporating Systemjs?

Seeking Answers Curious about the absence of systemjs.config.js file when using the new Angular2 CLI setup tool. Is there a way to install a basic version of Angular 2 without relying on the CLI tool available on angular.io? Past Experience In the past, ...

Using a configuration file with the JavaScriptServices React-Redux template

I have come across this question many times on different platforms, but I haven't been able to make it work for me. The issue is that I am using an API within a React component (with TypeScript 2.4.1 and webpack 2.5.1): .... fetch("some/url/api/", me ...

Tips for indicating errors in fields that have not been "interacted with" when submitting

My Angular login uses a reactive form: public form = this.fb.group({ email: ['', [Validators.required, Validators.email]], name: ['', [Validators.required]], }); Upon clicking submit, the following actions are performed: ...

Angular Workspace featuring a dynamic duo of Angular and Nativescript projects with shared code libraries

My project structure looks like this: AngularWorkspace/ |--app/ | | -- |--dist/ | |-- |--node_modules/ | |-- |--projects/ | |--library/ | |--AngularNativescriptAppOne/ | | |--App_Resources | | |--src | | | |--app/ | | | |--assets/ | | | ...

What prevents TypeScript from allowing an async function to return a combination of type T or Promise<T>?

During the development of my API in typescript, I encountered a situation where some controller actions can be synchronous while others cannot. To address this issue, I decided to specify a response type as follows: type ActionResult =IHttpActionResult | ...

multer strips the payload from the incoming request

When I make an http post request from a basic Angular application using FormData with the content type set to multipart/form-data, the backend processes the request using multer However, upon parsing the request with multer, the req.body always ends up be ...