Chiya Chiya - 1 year ago 97
jQuery Question

How do I get the value of an input element using angular.element('#id')

If I trying to get the value of input element using angular.element but its returning undefined value.
Here is my code:

$scope.registerUser = function() {

console.log(angular.element('#username').value); // undefined
console.log(document.getElementById('username').value); // seshu


How do I get the value using angular.element

Answer Source

You should use val method similar to jQuery's $.fn.val:


Alternatively you can use value property of the pure HTMLInputELement:


... because angular.element instance is an array-like collection of HTMLElements with every element accessible by its index.

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