Issue with AngularJS ng-click not firing function inside ui-gmap-window

section, I am encountering an issue with a click event that I have connected to a Google Maps info window using an <a> tag. Strangely, it seems that the function is not being triggered even though it shows as activated.

I attempted to rectify this by adding ng-app="" and ng-controller="", but unfortunately, my efforts were unsuccessful.

.controller('mainCtrl', function($scope, $rootScope, $stateParams,
            uiGmapGoogleMapApi, $cordovaGeolocation, $state, $firebase,
            $ionicModal) {
    var createMap = function(position){
        angular.extend($scope, {
            map: {center: {latitude: position.coords.latitude,longitude:position.coords.longitude},
                zoom: 13,
                markers: markersarray,
                options: {
                    // This is an example of a variable that cannot be placed outside of uiGmapGooogleMapApi without forcing of calling the google.map helper outside of the function
                    streetViewControl: false,
                    mapTypeControl: false,
                    scaleControl: false,
                    rotateControl: false,
                    zoomControl: false
                }, 
                events: {
                    click: function (map, eventName, originalEventArgs) {
                        var e = originalEventArgs[0];
                        Marker_Latt = e.latLng.lat();
                        Marker_Long = e.latLng.lng();
                        $scope.openModal();
                    }
                },
                markersEvents: {
                    click: function(marker, eventName, model, args) {
                        for(var i = 0; i < markersarray.length; i++){
                            if(markersarray[i].id === marker.key){
                                var content = '';
                                content += '<div ng-app="main" ng-controller="mainCtrl"><p>Added By: <a style="cursor: pointer;" [routerLink]="" (click)="navigatetoUser()">'+markersarray[i].username+'</a></p>';
                                content += '<p>Added On: ' + markersarray[i].date.toString() + "</p></div>";
                                navigateUserID = markersarray[i].userid;
                                createWindow(marker.get('map'), marker, content);
                               break;
                            }
                       }


                    },
                    dblclick:function(marker, eventName, model, args) {
                        console.log("double click!" + marker);
                    }
                },
            } 
        } );
    };

    $scope.navigatetoUser = function(){
        console.log("button clicked..");
        //$scope.data.selectedUserID = navigateUserID;
        //$state.go('userProfile', $scope.data);
    };
    function createWindow(map, marker, content){
        var infowindow = new google.maps.InfoWindow({
            content: content
         });
         infowindow.open(map, marker);
    }
  });

The navigatetoUser() function does not seem to be triggered, and I am unable to locate any errors in the code.


In the original code snippet:

    <ui-gmap-window isiconvisibleonclick="true">
      <p> {{CurrentMakerTitle}}
        <a href="" ng-click="$root.navigatetoUser()"> 
         {{CurrentMakerUserName}}
        </a>
        <br>{{CurrentMakerDateAdded}}
      </p>
    </ui-gmap-window> 
</ui-gmap-marker> 

I made alterations by changing it to infowindow since multiple windows tend to display the last-clicked information.

Answer №1

Gratitude to all those who provided feedback, I was able to resolve the issue by implementing the following solution:

click: function(marker, eventName, model, args) {
    for(var i = 0; i < markersarray.length; i++){
        if(markersarray[i].id === marker.key){
            navigateUserID = markersarray[i].userid;
            var content = '<p>Added By:  <a id="Info_'+marker.key+'" style="cursor: pointer;" [routerLink]="">'+markersarray[i].username+'</a></p>'
            content += '<p>Added On: ' + markersarray[i].date.toString() + "</p>";
            createWindow(marker.get('map'), marker, content, marker.key);**
           break;
        }
   }
}
function createWindow(map, marker, content, key){
        var infowindow = new google.maps.InfoWindow({
            content: content
        });
        infowindow.open(map, marker);
        google.maps.event.addListener(infowindow, 'domready', function() {
            var mapDiv = document.getElementById('Info_'+key+'');
            google.maps.event.addDomListener(mapDiv, 'click', function() {
                navigatetoUser();
            });
        });
    }

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

Prevent the running of JavaScript events initiated by a script fetched through AJAX

In my JS application, I am using AJAX to load different parts of the application. After the AJAX function is completed, the corresponding script is executed. However, I am facing an issue when trying to load a new part of the application. I need to find a ...

How to Use $scope within a Function in AngularJS

When a page is loaded, I run the following function: $scope.showTags = function(Id) { $scope.toggleSelectedBlocks = function selectB(block) { // There is a checkbox to be selected... } $scope.greetUser() { console.log("GREETIN ...

Experimenting with NGXS selectors: A comprehensive guide

Hey there, I am currently utilizing the NGXS state management library in my application. I have a selector set up like this and everything seems to be functioning correctly. However, while testing the app, I encountered the following error message: "PrintI ...

Ways to access Angular controllers from various folders

Yesterday, I dove into learning my first node.js/MEAN application and stumbled upon this helpful tutorial to kick-start my journey: https://scotch.io/tutorials/creating-a-single-page-todo-app-with-node-and-angular After following the tutorial and successf ...

Tips for effectively utilizing the else if statement in JavaScript

My current script for submitting a form using jQuery Ajax is mostly functioning as expected. However, I am experiencing an issue where only two responses are being triggered. The loading component works correctly, but the other response statements, includi ...

What is the best method to transfer text entered in one textarea to the output of another?

I recently picked up JavaScript again and encountered an issue while developing an app. I am struggling to pass input from one textarea to another, where the text should be converted to uppercase. I attempted to tweak code from w3, but I prefer to achieve ...

Determine the total value derived from adding two option values together

I am attempting to calculate the sum of two select options and display the result. So far, my attempts have only resulted in returning the value 1. What I am aiming for is to add the values from n_adult and n_children, and then show the total under Numbe ...

What could be the reason that data-bs-placement="right" is not functioning as expected?

I am facing an issue with the popover functionality in my project. No matter what value I set for data-bs-placement attribute, it does not display correctly. Can you help me understand why this is happening? <!DOCTYPE html> <html lang="en ...

What is the best way to transfer the $http response value to another function?

I currently have these two functions set up. One function, $scope.submit, handles posting data to the server and capturing the response value. The other function, $scope.addTeams, is responsible for adding teams based on the response from $scope.submit. ...

Bring in SASS variables to enhance Material UI theme in NextJS

Within my project, I currently have the following two files: materialTheme.ts import { createMuiTheme, Theme } from "@material-ui/core/styles"; const theme: Theme = createMuiTheme({ palette: { primary: { main: "#209dd2", contras ...

Exploring new possibilities in ChartJS with the use of multiple Y

I have successfully created a line chart using Chart.js with two datasets, each having its own Y scale and axis. The code for my datasets and options is as follows: datasets: [{ fill:false, label: 'Heat', yAxisID: "y-axis-1", da ...

Encountered a setback while trying to add information to a MySql database through Express

When I try to execute an insert query on a database, it throws the following error: code: 'ER_PARSE_ERROR', errno: 1064, sqlMessage: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio ...

Implementing jQuery form validator post anti-SPAM verification?

I am facing what seems like a straightforward JavaScript issue, but my knowledge in this area is still limited. Following a successful implementation of basic anti-SPAM feature that asks the user to solve a simple math problem, how can I integrate jQuery& ...

Obtain JSON data instead of XML data from a web service through Ajax with the option 'contentType' set to 'false'

Upon making an AJAX call to send an image file to one of my web service (.asmx) methods, I encountered a problem where the web service returns XML instead of JSON. This issue arose because I needed to set the contentType to false, in order to successfully ...

IE8 encountering issues with Jquery ajax() request

My current issue involves submitting data using ajax from forms with a class of ajax. This functionality works flawlessly in Firefox, Safari, and Chrome, but is unsuccessful in Internet Explorer. ajax: function() { $('form.ajax').live(&apo ...

How do I prevent an Angular directive from displaying HTML markup?

I am working with an angular directive: <some-dir text="{{characterDescription}}"></some-dir> app.directive('someDir', function() { "use strict"; return { restrict: 'E', transclude: false, ...

Discovering how to locate a div element in one component from a separate component using Vue.js

Imagine having multiple Vue.js components in one project. <loginFields></loginFields> <submitButton></submitButton> Now, when the submitButton (which is a div with a unique id) is clicked, I want to initiate a method that checks t ...

Tips for utilizing the Spacing Utility Classes in Bootstrap

While browsing through an article, I came across Bootstrap 4 Spacing Utility Classes, particularly the m-b-lg class used in the className section. <div class="row"> <div class="col-sm-6 m-b-lg"> <!-- column-small-50%, margin-bot ...

What are the benefits of using Express in NodeJS to run both a backend and a frontend server simultaneously?

My current project involves a simple NodeJS/AngularJS application structured as follows: /frontend/index.html <-- AngularJS home page /frontend/js/app.js <-- AngularJS app.js /backend/package.json<-- NodeJS package.json /backend/index.js < ...

Angular controller is failing to receive the dynamic JSON response from the RestAPI

Currently, I am working with JSON data retrieved from a REST API. I have successfully set up an alert that displays the JSON results within an $http.get function. Using a sample URL that contains test JSON data works perfectly fine and I receive the alert ...