1

I am trying to use jQuery Geocomplete with my AngularJS application.

I have this in my html page.

    <input id="destination-location-input" type="text" class="form-control"
     ng-model="destCtrl.destination" ng-change="destCtrl.locationChanged()" 
     data-geocomplete="street address" required/>

and added this code in controller.

var myElement = angular.element( document.querySelector('#destination-location-input'));    

myElement.geocomplete(
    {
      appendToParent: true,
      onChange: function(name, result) {
         var location = result.geometry.location;
      },
      onNoResult: function(name) {
         console.log("Could not find a result for " + name)
      }
    });

When run my app, I am getting this error.

TypeError: myElement.geocomplete is not a function

What could be the issue?

2 Answers 2

1

Make sure you include the Google Maps API with the Places Library before loading this plugin as described here

<script src="http://maps.googleapis.com/maps/api/js?libraries=places"></script>
<script src="jquery.geocomplete.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

Those are included
0

Use this;

var myElement = angular.element( document.querySelector('#destination-location-input'))[0];    

myElement.geocomplete(
{
  appendToParent: true,
  onChange: function(name, result) {
     var location = result.geometry.location;
  },
  onNoResult: function(name) {
     console.log("Could not find a result for " + name)
  }
});

4 Comments

are you use JQuery?
yeah. I am using JQuery
So Why you not write code like : $('#destination-location-input').geocomplete( { appendToParent: true, onChange: function(name, result) { var location = result.geometry.location; }, onNoResult: function(name) { console.log("Could not find a result for " + name) } });
Yeah. this works. but I am trying to use Angular way to obtain an element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.