The opacity of gmap-window cannot be defined because the property is undefined

Experiencing the following issue: Cannot set property 'opacity' of undefined

Here is the HTML and JavaScript code snippet:

<ui-gmap-window show="map.infoWindow.show" coords="map.infoWindow.center" options="map.infoWindow.options"></ui-gmap-window>

$scope.map.infoWindow.options.content = "<h1>....<div>....</div></h1>";

After investigating, it was discovered that the root cause of this error is due to using content object inside the infoWindow Options.

Further information can be found here

Following suggestions from the above source, the code was modified as below:

<ui-gmap-window show="map.infoWindow.show" coords="map.infoWindow.center" options="map.infoWindow.options">
                            {{ infoWindowContent }}
                        </ui-gmap-window>

$scope.infoWindowContent = "<h1>....<div>....</div></h1>";

While this modification solved the console error, the HTML content was not rendering properly. It is displaying the plain HTML string instead of converting it into DOM elements.

Is there any solution to address this rendering issue?

Answer №1

When using the ng-bind-html directive with the google.maps.InfoWindow, you may encounter issues, such as when trying to set the content property in the ui-gmap-window directive:

<ui-gmap-window show="infoWindow.show" coords='infoWindow.coords'>
          <div ng-bind-html="{{infoWindow.content}}"></div>
</ui-gmap-window> 

This can lead to the error you've been facing.

To address this, it's worth considering creating a custom directive to display InfoWindow content as HTML:

.directive('toHtml', ['$compile', function ($compile) {
        return {
            restrict: 'A',
            link: function link($scope, $element, attrs) {
                attrs.$observe('toHtml', function (value) {
                    if (value.length > 0) {
                        var $el = $compile(value)($scope);
                        $element.empty().append($el)
                    }
                })
            }
        }
    }])

Then, you can bind the HTML content like so:

<ui-gmap-window show="infoWindow.show" coords='infoWindow.coords'>
          <div to-html="{{infoWindow.content}}"></div>
</ui-gmap-window> 

For illustration purposes, here is an example setup:

angular.module('MapApp', ['uiGmapgoogle-maps'])

  
    .directive('toHtml', ['$compile', function ($compile) {
        return {
            restrict: 'A',
            link: function link($scope, $element, attrs) {
                attrs.$observe('toHtml', function (value) {
                    if (value.length > 0) {
                        var $el = $compile(value)($scope);
                        $element.empty().append($el)
                    }
                })
            }
        }
    }])

    .controller('MapCtrl', function ($scope, uiGmapGoogleMapApi, uiGmapIsReady) {

        $scope.map = {
            zoom: 4,
            bounds: {},
            center: {
                latitude: 40.1451,
                longitude: -99.6680
            },
            options: {}
        };

        $scope.infoWindow = {
            show: false,
            content: '',
            coords: {}
        };


        $scope.markers = [
            {
                latitude: 40.705565,
                longitude: -74.1180857,
                title: "New York",
                id: 1,
            },
            {
                latitude: 37.7576948,
                longitude: -122.4726193,
                title: "San Fransisco",
                id: 2,
            }
        ];

        uiGmapGoogleMapApi.then(function (maps) {

            $scope.showInfoWindow = function (marker, eventName, model) {
                $scope.infoWindow.coords.latitude = model.latitude;
                $scope.infoWindow.coords.longitude = model.longitude;
                $scope.infoWindow.content = "<h2>" + model.title + "</h2>";
                $scope.infoWindow.show = true;
            };

            $scope.closeInfoWindow = function () {
                $scope.infoWindow.show = false;
            };

        });
    });
.angular-google-map-container {
height: 30em;
}
<script src="https://code.angularjs.org/1.3.14/angular.js"></script>
<script src="https://rawgit.com/nmccready/angular-simple-logger/master/dist/angular-simple-logger.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-google-maps/2.2.1/angular-google-maps.js"></script> 
 
 <div ng-app="MapApp" ng-controller="MapCtrl">
        <ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="false" options="map.options" bounds="map.bounds">
            <ui-gmap-window show="infoWindow.show" coords='infoWindow.coords' closeClick="closeInfoWindow()">
                <div to-html="{{infoWindow.content}}"></div>
            </ui-gmap-window>
            <ui-gmap-markers models="markers" coords="'self'" options="'options'"  click="showInfoWindow">
            </ui-gmap-markers>
        </ui-gmap-google-map>
  </div>

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

the intricate dance between Node.js and the powerful V8 engine

Understanding the intricate relationship between nodejs and the v8 engine has been a challenge for me. When I write JavaScript code and run it, it is sent to the v8 engine for execution. If my code includes functions provided by nodejs, how does nodejs com ...

Building a unique directive in AngularJS that functions similarly to ng-required

I've dedicated around 4 hours to this task already. My goal is to create a custom directive similar to ng-required that handles input validation. Below is the code for ng-required: var requiredDirective = function() { return { restrict: ...

issue with unknown values in Vuejs array of objects

Struggling to create an array of objects, but encountering an issue where the first 83 objects are returning as undefined while only the last 4 have the correct data. Despite multiple attempts to refactor the code, a solution remains elusive. Here is the ...

Styling web pages with CSS, arranging circles in a

I am looking to create circular divs similar to the one in my code below. However, I want them to be stacked behind each other. Specifically, I would like a blue circle (that expands) positioned behind the current red circle but aligned center. The red cir ...

Tips for ensuring that an API waits for a loop to complete when searching for an array of IDs in SailsJs

When querying a table in my database using the find() method, I am returned with a record that includes a column containing an array of user IDs. My goal is to iterate through these IDs and use another find() method to retrieve the details of each user. ...

The absence of FormData.entries in submit is a limitation of the Vue framework

I recently created a Vue-App that consists of a simple form with just one <input name"surname"> and a <button type="submit">. The use case is to input "myname" and submit the form. However, when I initialize new FormData( ...

How to Properly Align Pagination in a Bootstrap 4 Column

I am currently using Bootstrap 4 and trying to center a pagination UL horizontally inside a grid column. Since the pagination is now displayed using flex, I am facing difficulties in getting it properly centered. I aim to achieve this without adding any e ...

Error: Google Maps not loading within an AngularJS modal

Currently, I am using AngularJS google maps to showcase a map with markers on my website. The situation is as follows: Initially, the Contact Details including fields like Door number, Street, Area etc. are displayed on a page along with a static map. Wh ...

Is it necessary for me to generate a mock or stub in order to evaluate the functionality of this asynchronous procedure?

I am looking to test a function that operates asynchronously within a specific class. Should I create a mock or stub for testing this function? If so, how would I go about creating one? delayedAlert(message: string, time: number, cb){ return ...

CSS Scroll Boundaries for an HTML Element

Is there a way to set scroll limits for an element that follows the page when scrolled so it doesn't go above or below certain parts of the page, such as the header and footer? I want it to remain within the body content when scrolling up or down. ...

Creating a conditional property in TypeScript based on an existing type - a comprehensive guide

Imagine if I had the following: type Link = { text: string; link: string; } interface BigLink extends Link { some: number; something: string; else: string; } However, there's a variable that shares all these properties except for the fact ...

Encountered an issue with a Node.js POST request leading to an error message: "socket hang up" with code 'ECONNRESET'

After creating a sample to send data to a REST service, I discovered that encountering non-ASCII or non-Latin characters (specifically in data.firstName) causes my post request using TEST-REST.js to throw: error: { [Error: socket hang up] code: 'EC ...

What is the method for customizing the color of a placeholder text in a specific text field

Is there a way to style placeholder text in different colors for each text field? According to the Mozilla documentation, the code snippet provided will change the color of the entire input tag. If you'd like to learn more, follow this link: https:/ ...

Guide on importing images from directories in Vue

As I delve into learning vue.js, a particular issue has surfaced. I am in the process of creating an SFC and encountering difficulties with loading images from the 'src / assets / logo.png' folder. Below is the code snippet: <template> & ...

How can Angular incorporate JSON array values into the current scope?

I am currently working on pushing JSON data into the scope to add to a list without reloading the page. I am using the Ionic framework and infinite scroll feature. Can someone please point out what I am doing wrong and help me figure out how to append new ...

The JavaScript slideshow fails to display an image during one rotation

The slideshow displays a sequence of images from pic1.jpg to pic8.jpg, followed by a 4-second pause with no image, and then repeats starting again at pic1.jpg. I am looking to have it loop back to pic1.jpg immediately after displaying pic8.jpg. Below is t ...

Is there a way to automatically change specific characters as a user types in an input field?

I'm facing an issue with replacing some characters dynamically. The goal is to ensure that user-input text is URL-friendly for constructing a URL: function slugify(string) { const a = "àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïí ...

Select the anchor attribute value of tabs using jQuery

After upgrading from jQuery 1.7 to 1.9, we encountered an issue with one of our functions no longer working. Our previous code used to retrieve the value of the anchor tag in the currently selected tab. select:function(event,ui) { var messageId=$(ui ...

Using a margin to refine an array of points in JavaScript

In my project, I am utilizing openCV.js for detecting contours in an image. Once the contours are identified, I proceed to implement certain filters and simplification techniques on these contours. Subsequently, I draw them as paths within an SVG for plott ...

Execute the dynamic key API function

Below is the data object: registration: { step1: { project: '', }, step2: { adres: '', facade: '', floor: '', }, }, An attempt is being ...