Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

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

Open
sison123 opened this issue Mar 1, 2018 · 4 comments
Open

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

sison123 opened this issue Mar 1, 2018 · 4 comments

Comments

@sison123
Copy link

sison123 commented Mar 1, 2018

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
Copy link
Owner

allenhwkim commented Mar 1, 2018

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
Copy link

SISONKK commented Mar 27, 2018

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
Copy link
Owner

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
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants