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

Can someone guide me on identifying the type of object in React/Typescript?

Can anyone help me remove this unnecessary definition? const [nextLocation, setNextLocation] = useState(null) as any[]; I have been struggling with this in my React Router 6 project. I've looked through the documentation but haven't found a suit ...

Angular: Exploring the possibilities of condition-based click event implementation

In my component, there are two elements: 'order information' and a 'datepicker'. When clicking on the component, it will display the order information. However, I want to prevent the click event from being triggered if the user clicks ...

Entering key-value pairs into a dictionary to show correlation

I've been struggling to find a solution for what seems like a simple issue. The problem lies in typing a dictionary with values of different types so that TypeScript can infer the type based on the key. Here is the scenario: type Id = string; inter ...

Creating an array of objects data is a breeze with Vue.js

I have an array of data containing selected items, and I need to extract the IDs from this array into a new array so that I can send only the IDs to the back-end. Sample Code method toggleSelection(rows) { console.log('this.multipleSelection : &a ...

Anticipated the object to be a type of ScalarObservable, yet it turned out to be an

When working on my Angular project, I utilized Observables in a specific manner: getItem(id): Observable<Object> { return this.myApi.myMethod(...); // returns an Observable } Later, during unit testing, I successfully tested it like so: it(&apos ...

Laravel 5.4 integrates with Angular4: Implementing Passport token requests

Trying to make a Token request from API using: Signin(email: string, password: string): void { let data: Object = { client_id: 2, client_secret: 'vSFxVqALQHjyotPyGfhrGj3ziudUGsts2ZWiAGms', grant_type: 'password&a ...

Guide for setting up filtering and sorting on a multi-value array column with MUI's data grid

I've encountered an issue with the MUI Data Grid component's free version, specifically regarding filtering and sorting on a column that displays multiple values in an array. The problematic column in this case is 'tags', which showcase ...

Can Next.js accommodate server-side redirection with internationalization?

I'm working on a small Next.js app that has pages accessible only to logged in users. To manage the authenticated routes, I created an HOC (withAuth) that handles redirection on the server side to prevent page flashing on the client side. Everything i ...

When using tsdx with React, null values can prevent proper usage of hooks

Recently, I attempted to develop a React TypeScript component using tsdx for compilation and encountered a roadblock while debugging. The package appears to be successfully published and installed without any errors. However, when trying to use it, I consi ...

What sets a module apart from a script?

As I delve into the depths of TypeScript documentation to grasp the concept of modules, particularly ES6 modules, I stumbled upon some interesting insights. typescript-modules - this documentation talks about typescript modules and highlights an important ...

conditional operator that compares values in router events

As I examine an object, links = { link1: 'page1', link2: 'page2', link3: 'page3', link4: 'page4', link5: 'page5', link6: 'page6' } I possess a function for retrieving t ...

Duplicate a DOM element and incorporate animation into it

After extensively researching articles and documentation on this topic, I have yet to find a solution that aligns with the approach I am attempting to implement. My scenario involves an array of category items which contain a nested array of products be ...

The dropdown feature in Bootstrap 5 seems to be malfunctioning in Angular 12

I am facing issues while trying to implement the Bootstrap 5 dropdown in Angular 12. After installing all required packages and adding them to the angular.json file, I still cannot get it to work properly. Even after copying the example directly from the ...

Are there alternative methods for incorporating react-multi-carousel in a project utilizing NEXT.js and React/Typescript?

I installed the react-multi-carousel module and configured a simple carousel, but it's not functioning properly. The issue seems to be related to the absence of <li> tags. Here is the HTML that was rendered: <ul class="react-multi-caro ...

Why is my Angular promise unexpectedly landing in the error callback?

I am facing an issue with my Angular + Typescript client. I have developed a PHP API and need to send a post request to it. Upon receiving the request, the server fills the response body with the correct data (verified through server debugging). However, w ...

Creating a custom Angular 2 component with specified HTML template content

I am currently working with Angular 2 and @ng-bootstrap. In my project, I have a modal dialog set up as follows: <template #editDialog let-c="close" let-d="dismiss"> <div class="modal-header"> <button type="button" class="close" ...

The distinction between <Type>function and function name():Type in TypeScript is essential to understand the various ways

function retrieveCounter(): Counter { let counter = <Counter>function (start: number) { }; counter.interval = 123; return counter; } Upon inspection of line 2 in the code snippet above, I am left wondering why I am unable to use function ...

How to Properly Convert a Fetch Promise into an Observable in Ionic 5 using Typescript?

I'm in the process of transitioning my Ionic3 app to Ionic5 and currently working on integrating my http requests. I previously utilized angular/http in Ionic3, but it appears that it has been deprecated. This was how I handled observables in my code: ...

How to dynamically style a NgBootstrap modal in Angular during runtime

One of the features of my application is the ability to swap themes at runtime. The primary component in my app is called BaseComponent, which is added to my AppComponent and includes a theme property. This theme property represents a class that is applie ...

How come TypeScript remains silent when it comes to interface violations caused by Object.create?

type Foo = { x: number; }; function g(): Foo { return {}; // Fails type-check // Property 'x' is missing in type '{}' but required in type 'Foo'. } function f(): Foo { return Object.create({}); // Passes! } functio ...