MohanKanal
MohanKanal

Reputation: 71

Get angular ng-model value in javascript

Just i want to get the ng-model hidden field value using javascript.

<input type="hidden" name="Latitude" id="sLatitude" ng-model='sLatitude'>

Upvotes: 5

Views: 14629

Answers (6)

vassilis ntovantzis
vassilis ntovantzis

Reputation: 352

it took me some time to find out, but I think the answer is

angular.element(YOUR_ANGULAR_ELEMENT_HERE).attr('ng-model');

As an answer you 'll get the value of the ng-model, "sLatitude".

I am leaving it here just in case someone else needs it.

Upvotes: 2

user3414092
user3414092

Reputation: 77

You can get the value of Latitude by $scope.

var latitudeValue = $scope.sLatitude;

OR

if you have value attribute in input control then

var latitudeValue = document.getElementsById("sLatitude").value;

Upvotes: 0

RaviSoni-Systematix
RaviSoni-Systematix

Reputation: 99

You can get the value of Latitude by write this in java script in your controller like this. var latotudeValue = $scope.sLatitude;

Upvotes: 0

Vasyl
Vasyl

Reputation: 1424

You can access by calling:

angular.element(document.getElementById('sLatitude')).scope().sLatitude

Upvotes: 0

Jameel Mohammed
Jameel Mohammed

Reputation: 2364

If you want that value within scope , just access as $scope.sLatitude

If you want that value outside the scope, document.getElementById("sLatitude").value

Upvotes: 0

Hajji Tarik
Hajji Tarik

Reputation: 1082

you can get sLatitude value by :

console.log($scope.sLatitude);

Upvotes: 0

Related Questions