user3373877
user3373877

Reputation: 325

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.

Upvotes: 9

Views: 23236

Answers (2)

ug_
ug_

Reputation: 11440

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

Upvotes: 24

Saqib R.
Saqib R.

Reputation: 3069

By ID

document.getElementById('yourId').value

By Name

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

Keep it simple :)

Upvotes: 1

Related Questions