Issue encountered when attempting to trigger an ionic modal from a custom control in Google Maps

I am facing an issue with my custom Google map control in Ionic framework. I want the control to open a modal when clicked, but I keep getting an error "Cannot read property '$$destroyed' of undefined" when I try to do so. On the other hand, another control that clears markers is working perfectly fine.

When I set modal.show as the function for the button, I encounter the mentioned error upon clicking it. However, if I use modal.show(), the modal opens automatically when the page loads, which is not desired, and then refuses to open again upon button click.

Controller

.controller('MapCtrl', function(mapServ, mapFact, $ionicModal, $scope){
  var vm = this;

  var gmap = mapServ.init();
  var markers = mapServ;

  // Creating Modal and Custom Map Controls
  $ionicModal.fromTemplateUrl('templates/modal.html', {
    scope: $scope
  }).then(function(modal) {
    vm.modal = modal;

    var controlContainer = document.createElement('div');
    var clearControl = new mapFact.Control(controlContainer, 'Clear Map', mapFact.clearMap);
    var locControl = new mapFact.Control(controlContainer, 'Locations', vm.modal.show());

    controlContainer.index = 1;
    gmap.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlContainer);
  });

   // Adding Markers
   mapFact.markers($rootScope.rests, gmap).then(function(results) {
   mapServ.markers = results;
   vm.markers = mapServ.markers;
 });
});

From the Factory

// Button Constructor
map.Control = function(controlDiv, text, func) {
  // Setting CSS for the control border.
  var controlUI = document.createElement('div');
  controlUI.style.backgroundColor = '#ed5929';
  controlUI.style.border = '2px solid #ed5929';
  controlUI.style.borderRadius = '3px';
  controlUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
  controlUI.style.cursor = 'pointer';
  controlUI.style.marginBottom = '22px';
  controlUI.style.marginRight = '22px';
  controlUI.style.marginTop = '22px';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Click to toggle markers';
  controlDiv.appendChild(controlUI);

  // Setting CSS for the control interior.
  var controlText = document.createElement('div');
  controlText.style.color = 'rgb(255,255,255)';
  controlText.style.fontWeight = 'bold';
  controlText.style.fontFamily = 'Roboto,Arial,sans-serif';
  controlText.style.fontSize = '16px';
  controlText.style.lineHeight = '38px';
  controlText.style.paddingLeft = '5px';
  controlText.style.paddingRight = '5px';
  controlText.innerHTML = text;
  controlUI.appendChild(controlText);
  controlUI.addEventListener('click', func);
};

Answer №1

There are a couple of methods to incorporate a modal in Ionic as outlined in the Ionic - Modal Implementation Guide.

You have the option to either include a separate template or embed it within the main HTML file using script tags. First, you must link your modal to the controller and then create the modal itself. Next, define functions for opening the modal that will be activated. Lastly, add a button that triggers modal.show() to open the modal.

Example snippet of HTML Code:

<button class = "button" ng-click = "openModal()"></button>

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

How can I code a script to import JSON data into MongoDB database?

I have a JSON file named "data.json" that contains an array of people's names as shown below: "data": [ { { "name":"John", "age":30, } { "name":"Mark", "age":45, } } ] I am ...

Highcharts displays data with the fourth y axis but doesn't include labels for it

I'm facing an issue with displaying all the labels on my chart. I have 4 series plotted and decided to add two y-axes on each side of the graph, but the labels for the last series named "Stuff Data" are not showing up correctly. Instead, it seems to b ...

Reiterate list of inquiries using InquirerJS

How can the questions be reset or have a specific answer lead to another previous question? var questions = [{ { name: 'morefood', message: 'Do you want more food?', ...

Tips for shuffling questions within arrays

var quiz = [ { "question" : "Q1: What is the greatest invention of all time?", "choices" : [ "Wheel", "Electricity", ...

Submit a data array using formData through axios

I am planning to send array data using formData. The backend is set up to accept the data array separated by a dash ; For example, if I were to use Postman and input the form-data like this: id_barang : 122;288;383 (sending 3 values of id with dashes ;) W ...

Is it possible to submit form data to multiple destinations in an HTML form submission?

I am in the process of developing a quiz application that consists of two essential files: question.php and process.php Within question.php, the user is required to input their answer in a textbox and submit it by clicking a designated button. This input ...

Using logical equality operators in Javascript

Imagine I have two boolean variables and I need to determine when they are both true or false, essentially requiring a logical equality operator.' Most JavaScript resources recommend using bitwise operators, with the XOR operator performing a similar ...

What is the best way to implement Media Queries in the Next.js application Router?

I am currently working with Next.js 13 and the App Router. Within my client component, I have implemented media queries in JavaScript to customize sidebar display for small and large screens. "use client"; export default function Feed() { co ...

What is the best way to establish a link between two containers?

Currently, my focus is on developing a unique component that poses a challenge with the connection between two containers. Specifically, I am working on crafting a sign-up form for users that comprises four distinctive sections. Each section triggers its o ...

Gather various data from multiple tables with Laravel

I am seeking help to find a solution to my current issue. I am working with various tables and wondering how I can create a custom collection that gathers specific data from multiple tables based on logical relationships. My goal is to return this collec ...

What is the best way to iteratively fade in data from a MySQL database one by one?

How can I load data from a MySQL database and display it one by one with a fade-in effect? Let's say I have a total of 40 images stored in the database. First, I want to display each image like this: <li class="img" style=" list-style: none; flo ...

Chrome browser is experiencing an issue with the Modal RadWindow not closing properly

In my main "Report" page, there are actions available to the user that open a modal RadWindow. The user can then take actions within the modal window, click Save, and the modal window should close while the main grid refreshes. While this functionality wo ...

Using JQuery to assign a parent class to a link within a child element

I am currently developing a Chrome extension for a forum. Here is a snippet of HTML code extracted from a thread page: <div class="body_message" data-message-id="198342" data-topic-id="2876" data-user-id="1769"> <div class="uk-grid post_wrapp ...

Unintended redirects are occurring with AJAX requests when using the send() method

After loading the web page, I utilize AJAX to populate a list asynchronously. However, when the AJAX request is sent to retrieve data for the list box, instead of receiving JSON data as expected, an unintended web page containing the list box is returned. ...

Having some success with AngularJs autocomplete feature

Currently working on a small search application that utilizes Elasticsearch and AngularJS. I have made progress in implementing autocomplete functionality using the AngularJS Bootstrap typeahead feature. However, I am encountering difficulties in displayin ...

Upcoming API and backend developments

When working with the NEXT project, API Routes provide the ability to create an API endpoint within a Next.js application. This can be achieved by creating a function in the pages/api directory following this format: // req = HTTP incoming message, res = H ...

Can a single controller function in ASP.NET MVC4 be used to send back two arrays to the view?

Continuing from my previous query here, I am working with a model called SchoolTestsPerModulePerStudent which looks like this: public partial class SchoolTestsPerModulePerStudent { public long StudentID { get; set; } public long ModuleID { get; se ...

I am noticing multiple quantities of the same item being added to my shopping

Recently, I encountered a problem with my online shop that seems to be related to the Javascript. The issue arises when I add an item to my shopping cart from this particular page: . Initially, when I click 'Add to Cart,' the item is correctly ad ...

Utilize the "don't get terminated" app

Currently, I am working on implementing a middleware in my application to check for the presence of a token on all routes. For testing purposes, I have decided to focus on the /users route. In order to achieve this, I made the following adjustments to my a ...

When using React, appending a React Link tag to an existing list item may result in the addition of two objects instead of the desired

Trying to create a loop that checks if an object's date matches with a date on a calendar. If it does, I want to add a React Link tag to the respective li element. The loop logic works well, but the issue is when appending the Link tag using createTex ...