How do I get the value of an input element using angular.element('#id')
Explanation
You should use val
method similar to jQuery's $.fn.val
:
console.log(angular.element('#username').val());
Alternatively you can use value
property of the pure HTMLInputELement:
console.log(angular.element('#username')[0].value);
... because angular.element
instance is an array-like collection of HTMLElements with every element accessible by its index.
Correct approach
But... You should never read input value like this in context of Angular app. Instead, use ngModel directive and bind input value to angular model directly:
$scope.registerUser = function() {
console.log($scope.username);
};
where in HTML you have
<input type="text" ng-model="username">
This works for me
angular.element(document.getElementById('username')).val();