allenhwkim / angularjs-google-maps

The Simplest AngularJS Google Maps V3 Directive
http://ngmap.github.io
MIT License
1.52k stars 517 forks source link

cannot pass parameter in on-place-changed event #862

Open sison123 opened 6 years ago

sison123 commented 6 years ago

im using place-auto-complete in an array as follows,

<div ng-repeat='data in list'>
 <input places-auto-complete ... on-place-changed="placeChanged(data)" />
 </div>

$scope.placeChanged = function (data) { console.log(data) // seems undefined here };

is there any other way to solve this issue..!!

allenhwkim commented 6 years ago

it seems working for me. documentation might be incorrect.

Please follow this example, https://ngmap.github.io/#/!places-auto-complete.html

this.getPlace()

ng-repeat with data might cause an issue

SISONKK commented 6 years ago

this.getPlace() -- this code works for me as well. my issue is,

i cant pass a paramter to placeChanged function; on-place-changed="placeChanged(data)"

it seems the data is undefined in following code,

$scope.placeChanged = function (data) { console.log(data) // seems undefined here };

is there any solution for this..?

allenhwkim commented 6 years ago

This is the same as, https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

You need to get the data from your scope, not from your parameter.

langdonx commented 6 years ago

Is it possible that this can be changed? Are you open to PRs?

My controllers are written with classes, so there's no decent way gain access to $scope or my controller instance.

HTML:

<input ... places-auto-complete on-place-changed="$ctrl.onMapAutocompleteSelect('asdf')">

Controller:

export default class {
  constructor($element, $q, $scope, ApiService, Logger) {
    'ngInject';

    Object.assign(this, { $element, $q, $scope, ApiService, Logger });
  }

  $onInit() {
    this.loadCountries();
  }

  onMapAutocompleteSelect(arg) {
    console.log('arg', arg); // can't pass any args
    console.log('this', this); // this does not reference my controller instance
    console.log('this.getPlace', this.getPlace()); // there's no way to get any reference to the html elements used
  }
}

The only thing I can seemingly do is define a variable outside of my class, and assign it in $onInit, which limits me to 1 instance of this controller at a time.