Chiya Chiya - 3 months ago 5x
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


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.