khan khan - 1 year ago 65
AngularJS Question

On values from script function to input field ng-model gives undefined Angular

I am using google maps in my application in which i use maps related code in script tag and on after the search result it gives longitude, latitude and i am getting these values and showing these values in input

here is my part of script code which passes lon and lat to input

document.getElementById('lat').value =;

document.getElementById('lng').value = place.geometry.location.lng();

here is my HTML code

<div class="from-group">
<li>Latitude: <input class="from-control" ng-model="" id="lat"></li>
<li>Longitude: <input class="from-control" ng-model="formData.lng" id="lng" ></li>
<button class="btn btn-primary" ng-click="values()" id="idbtn" >Results</button>

but it gives undefined for ng-model="formData.lng" and when i enter some thing
manually it works fine but when values comes from script it gives undefined

here is my controller code

$scope.values = function () {


Answer Source

When you pass the lat and long from your javascript file with

document.getElementById('lat').value =;
document.getElementById('lng').value = place.geometry.location.lng();

The ng-model is not getting updated or 'triggered'



there is a good post here that may help.

You may consider using a google maps directive such as ng-map

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