How to set the input field value dynamically in AngularJS ? Last Updated : 30 Jul, 2024 Suggest changes Share Like Article Like Report Given an input field and the task is to set the input field value dynamically with the help of AngularJS.Approach: A value is being set to the input field despite the user enter something or not. ng-click event is used to call a function that sets the value to 'This is GeeksForGeeks' with the help of ng-model.Example 1: In this example, the input field is read-only So the user can not modify it and the value is set dynamically. HTML <!DOCTYPE HTML> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = angular.module("app", []); myApp.controller("controller", function ($scope) { $scope.nameText = ''; $scope.setVal = function () { $scope.nameText = "This is GeeksForGeeks"; }; }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p> How to set the <input> field value dynamically in AngularJS </p> <div ng-app="app"> <div ng-controller="controller"> Input field: <input type="text" readonly name="mytext" ng-model="nameText"> <br><br> <input type="button" ng-click="setVal()" value="Set Dynamically"> <br> </div> </div> </body> </html> Output:Example 2: In this example, user can modify the input field but the value entered by user can be set dynamically. HTML <!DOCTYPE HTML> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = angular.module("app", []); myApp.controller("controller", function ($scope) { $scope.nameText = ''; $scope.setVal = function () { $scope.nameText = "This is GeeksForGeeks"; }; }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p> How to set the <input> field value dynamically in AngularJS </p> <div ng-app="app"> <div ng-controller="controller"> Input field: <input type="text" name="mytext" ng-model="nameText"> <br> <br> <input type="button" ng-click="setVal()" value="Set Dynamically"> <br> </div> </div> </body> </html> Output: Advertise with us Next Article How to set the input field value dynamically in AngularJS ? P PranchalKatiyar Follow Similar Reads How to add input fields dynamically on button click in AngularJS ? The task is to add an input field on the page when the user clicks on the button using AngularJs. Steps: The required component for the operation is created (add-inputComponent). In that component, html file (add-input.component.html) required html is written. In that HTML, the main div for input fi 2 min read How to set focus on input field automatically on page load in AngularJS ? We can focus on any input field automatically using the angular directives. Here we create a custom directive that can auto-focus on any field in the form. Creating a custom directive is just like creating an Angular component. To create a custom directive we have to replace @Component decorator wit 3 min read How to fetch the details using ng-repeat in AngularJS ? In this article, we will see how to fetch the details with the help of the ng-repeat directive in Angular, along with understanding its implementation through the illustrations. AngularJS contains various types of pre-defined Directives, where most of the directives start with ng which denotes Angul 2 min read How to get the value of the form in Angular ? In this article, we are going to see how to get value from the form in Angular 10. We will use AbstractControl value property to get the form value in an object. Syntax: form.value Return Value: object: It is an object containing form value Approach:Â Create the Angular app to be usedIn app.componen 1 min read How to Filter Multiple Values in AngularJS ? AngularJS is one of the popular frameworks of many web developers to create dynamic single-page web applications. To make the application more and more dynamic, we can use the filtering of data feature to dynamically show the data to the user as per the input or selection. These provide a better use 6 min read Article Tags : Web Technologies HTML AngularJS HTML-Misc AngularJS-Misc +1 More Like