Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the hidden input's value by using angularjs?

In angularjs,I want to get the value of the hidden input. such as the following:

<pre>
<input type="hidden" name="captId" value="AqXpRshs9QHfxUbOWqMT" ng-model="captId">
</pre>

How to get the "hidden input" value "AqXpRshs9QHfxUbOWqMT" by using angularjs,not ajax or jquery.

like image 561
user3373877 Avatar asked Mar 03 '14 07:03

user3373877


2 Answers

By ID

document.getElementById('yourId').value

By Name

document.getElementsByName('yourName')[0].value

Keep it simple :)

like image 162
Saqib R. Avatar answered Sep 17 '22 09:09

Saqib R.


You can use ng-init to initialize the value so it binds that to your model variable upon creation.

<input type="hidden" name="captId" ng-init="captId='AqXpRshs9QHfxUbOWqMT'" ng-model="captId">

Or you can get it directly if all else fails:

angular.element(document.getElementsByName('captId')[0]).val();
// or dont use angular at all
document.getElementsByName('captId')[0].value

Documentation for angular.element

like image 36
ug_ Avatar answered Sep 18 '22 09:09

ug_