Cheng Cui
Cheng Cui

Reputation: 31

Ember google map event handling function cannot get `this`

in my controller i have following action:

actions: {
changeCenter: function(event) {
  this.set('mapLat', event.latlng.lat());
  this.set('mapLng', event.latlng.lng());
}}

in my template i am using it as

{{g-maps 
name="my-map" 
lat=mapLat lng=mapLng zoom=zoom
circles=circles
showMapTypeControl=false
showScaleControl=false
click=actions.changeCenter}}

but when the function is trigger, the this keyword is undefined. Could some one give me some hint here? thanks.

Upvotes: 1

Views: 43

Answers (1)

ykaragol
ykaragol

Reputation: 6221

Use it as closure action such as (action 'actionName'):

{{g-maps 
  name="my-map" 
  lat=mapLat lng=mapLng zoom=zoom
  circles=circles
  showMapTypeControl=false
  showScaleControl=false
  click=(action 'changeCenter')}}

Upvotes: 2

Related Questions