AngularJS supports .val() jQuery functionality. Here in below examples we can see how to read value of an element.

Using ng-model

ng-model is directive to hold input variable
<input ng-bind="val" value="default value"/>
<br/>
{{val}}
<script>
function myCtrl($scope) {
    $scope.val = 'my val var'; 
}
</script>
Try It Your Self

Steps to read input value using Angular Element:

  1. Get angular element of html element
  2. Use .val() method to read input value
var myEl = angular.element( document.querySelector( '#inputID' ) );
myEl.val();

Steps to set input value using Angular Element:

  1. Get angular element
  2. Use .val('value') method to set value
var myEl = angular.element( document.querySelector( '#inputID' ) );
myEl.val('my value');

1 comment:

  1. As a beginner this helps to learn AngularJS. Thanks for sharing this, Bookmarked

    Related Topic: http://www.credosystemz.com/training-in-chennai/best-angularjs-training-in-chennai/

    ReplyDelete

Blogroll

Follow this blog by Email

Popular Posts