user1180888 user1180888 - 1 year ago 136
Javascript Question

ng-click Error: [$parse:syntax] Syntax Error: Token 'Object' is unexpected, expecting []]

I'm reverse geocoding when a user clicks on a point on a google map like so:

geocoder.geocode({'location': latlng}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[1]) {

At this stage the console log for results[1] looks like

Object {address_components: Array[4], formatted_address: "Rathmines, Co. Dublin, Ireland", geometry: Object, place_id: "ChIJN6MDC6kOZ0gRIhArCabX9o4", types: Array[2]}

But then I try and pass that object in to an ng-click function when the user taps on the infowindow with the address that I have popping up, like so:


I get the error

Error: [$parse:syntax] Syntax Error: Token 'Object' is unexpected, expecting []]
at column 23 of the expression [addressPicked([object Object])] starting at [Object])].

I have this working in another application, but I am just passing through a lat & long string.

Do I need to convert the object to something else before trying to pass it through as a parameter?

Anyone come across this error before with ng-click?

Any help would be much appreciated, thanks.

Answer Source

Without looking at the full code, my guess is that you are getting the error because


is converting results[1] to its string representation [object Object] and hence the error.

Try using without inner quotes

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download