The issue with calling a public method from an onchange event triggered by a custom Google Maps control in the Ionic framework has been encountered

Hello, fellow developers! I am relatively new to Ionic and web programming in general. Currently, I am working on a small app that involves integrating the Google Maps JS API. While I have successfully created and loaded the map, as well as added a custom control (a dropdown select menu) to it, I am facing an issue with executing a specific function named 'openListCuaHangModal' from the onchange event. Every time I try to do so, I encounter the error "this.openListCuaHangModal is not a function". Any help or insights would be greatly appreciated. Thank you in advance.

Below is a snippet of the code from the .ts file:

export class ChonDiemGiaoDichPage {

  @ViewChild('map') mapElement: ElementRef;
  map: any;
  public diemGiaoDich: any;

  constructor(public modalCtrl: ModalController, public navCtrl: NavController, public http: Http, public navParams: NavParams, public viewCtrl: ViewController, public geolocation: Geolocation) {
  }

  ionViewDidLoad() {
    this.diemGiaoDich = this.navParams.get('results');
    console.log(this.diemGiaoDich);

    **//This is where the map is being loaded**
    this.loadMap(this.modalCtrl, this.openListCuaHangModal);

  }  
  addInfoWindow(marker, content) {

    let infoWindow = new google.maps.InfoWindow({
      content: content
    });

    google.maps.event.addListener(marker, 'click', () => {
      infoWindow.open(this.map, marker);
    });

  }
  **//The function I am attempting to call**
  openListCuaHangModal(khuvuc) {
    let myModal = this.modalCtrl.create(ListCuaHangPage, khuvuc);
    myModal.present();
  }

  loadMap() {
    //Use dynamic geolocation
    this.geolocation.getCurrentPosition().then((position) => {

      let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
      //Set options for the map
      let mapOptions = {
        zoomControl: true,
        mapTypeControl: false,
        scaleControl: false,
        streetViewControl: false,
        rotateControl: false,
        fullscreenControl: false,
        center: latLng,
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: [
          { elementType: 'geometry', stylers: [{ color: '#242f3e' }] },
          { elementType: 'labels.text.stroke', stylers: [{ color: '#242f3e' }] },
          { elementType: 'labels.text.fill', stylers: [{ color: '#746855' }] },
          ...
        ]
      }
      //Initialize the map
      this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);

      //Add custom control
      var centerControlDiv = document.createElement('div');
      ...
      </select>';
      }
      else
        console.log("Khong thay diem GiaoDich");
      controlUI.appendChild(controlText);

      //Setup click event listeners for the custom control
      controlUI.addEventListener('click', function () {
        //map.setCenter(chicago);
      });
      this.map.controls[google.maps.ControlPosition.TOP_CENTER].push(centerControlDiv);

      //Set marker for the current location
      ...
    }, (err) => {
      console.log(err);
    });
  }
}

Answer №1

Since I am unable to leave a comment, I will provide my response here.

The onchange function that you are attempting to invoke is not within the scope of the class ChonDiemGiaoDichPage. Therefore, it cannot be located.

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 issue of `Console.log` displaying as undefined arises after subscribing to a provider in Ionic3

In the process of implementing the Spotify api into my Ionic 3 app, I encountered an issue where the data retrieved appears as undefined when attempting to log it. Let me share some code and delve deeper into the problem. Here is the function getData() tha ...

Troubleshooting Angular MIME problems with Microsoft Edge

I'm encountering a problem with Angular where after running ng serve and deploying on localhost, the page loads without any issues. However, when I use ng build and deploy remotely, I encounter a MIME error. Failed to load module script: Expected a ...

Invoking a controller from another controller in the Express framework using Typescript

Currently, I am trying to call a controller from another controller in my code. While attempting to pass parameters using {params: {task_id: String(task_id), result}}, TypeScript is flagging an error indicating that res does not have all the required attri ...

Avoid triggering the onClick event on specific elements in React by utilizing event delegation or conditional rendering

programming environment react.js typescript next.js How can I prevent the onClick process from being triggered when the span tag is pressed? What is the best approach? return ( <div className="padding-16 flex gap-5 flex-container" ...

"String representation" compared to the method toString()

Currently, I am in the process of writing unit tests using jasmine. During this process, I encountered an issue with the following code snippet: let arg0: string = http.put.calls.argsFor(0) as string; if(arg0.search(...) This resulted in an error stating ...

"Error: The property $notify is not found in the type" - Unable to utilize an npm package in Vue application

Currently integrating this npm package for notification functionalities in my Vue application. Despite following the setup instructions and adding necessary implementations in the main.ts, encountering an error message when attempting to utilize its featur ...

Tips for neatly wrapping a class constructor

Currently, I am experimenting with code to create a more streamlined Angular Dialog initializer. This initializer should be passed a constructor function along with its arguments in a type-safe manner. The current implementation works, but it is challengi ...

Validation of email forms in Angular 5

I have encountered a challenge that I need help with: Using Angular 5 - template driven form In my template, there is an input field with the type email. Here's an example: <input type="email" [(ngModel)]="model.email" #email="ngModel" email /> ...

Getting js.map Files to Function Properly with UMD Modules

I am experiencing an issue with debugging TypeScript files in Chrome and Firefox. Specifically, when trying to debug the MapModuleTest.ts file, the debugger seems to be out of sync with the actual JavaScript code by two lines. This discrepancy makes settin ...

Sharing events between disparate components in Angular

Is there a way in Angular to trigger an event within one component and then have another completely unrelated component listen for that event? These components do not share a parent or have any sort of parent-child relationship. I'm trying to find a s ...

Ways to remove redundant code from multiple service calls

Within my DataService, I have set up an observable for various API calls. I am looking to streamline the process by creating a reusable block of code to be used in each HTTP request. export class DataService { constructor( private http: HttpClient, ...

The concept of passing arguments in Typescript

During my experience with Typescript programming, I encountered a situation like the one described below. If I pass an argument containing an object with the same name as the parameter defined in the function signature, Typescript recognizes it, but not ...

I encountered an issue while making customizations to my default next.config.js file. Despite attempting various solutions, I consistently encountered an error regarding the invalid src property

I'm currently trying to introduce some custom configurations into the next.config.js file. However, I keep encountering an error regarding an invalid src prop. Despite my attempts to troubleshoot in various ways, the error persists. // ...

The challenge with the Optional Chaining operator in Typescript 3.7@beta

When attempting to utilize the Typescript optional chaining operator, I encountered the following exception: index.ts:6:1 - error TS2779: The left-hand side of an assignment expression may not be an optional property access. Here is my sample code: const ...

Detecting Changes in the Backend with Angular

I'm curious about the best way to notify the frontend when there is a change in the backend. How can this situation be effectively handled? While developing an application on Azure, I have considered two possibilities, but none of them seem ideal. The ...

Ways to retrieve form information from a POST request

I received a POST request from my payment gateway with the following form data: Upon trying to fetch the data using the code snippet below, I encountered errors and gibberish content: this.http .post<any>('https://xyz.app/test', { ti ...

Master the art of seamlessly switching between multiple kendoGridDetailTemplates in the Kendo Angular DataGrid

I am working with a Kendo DataGrid and I'm looking to use it with multiple kendoGridDetailTemplate variations. Here is an example of the kendo detail grid structure: <ng-template kendoGridDetailTemplate let-dataItem > <div>{{dataIte ...

Having trouble accessing @ViewChildren from the parent component

I've been facing an issue while attempting to control the child instances of a component and I can't seem to bypass this particular error. I've been referring to solutions provided on this specific thread. The main component Sequence houses ...

Converting numbers to strings based on locale in React Native

I have a quantity that, when using the amount.toFixed() function, produces the string "100.00". I would like this result to be formatted according to the specific locale. For example, in Italian the desired output is 100,00, while in English it should be ...

Tips on accessing validator errors in Angular

Is there a way to extract the value from the 'minLength' validator error in order to use it in a message? This is my current HTML setup: <div class="mt-2" *ngIf="ngControl.control.errors?.minlength"> {{ &ap ...