Set textarea value in AngularJs
Set textarea value in AngularJs – It is very simple to set the value attribute of the input field. Here in this tutorial we are going to explain how you can set the textarea value using angularjs. You can also use our online editor to edit and run the code online.
How to set textarea value in AngularJs | Example
Let us go step by step to set the textarea value example –
JavaScript Part
JavaScript Part Contains the following part as below –
Angularjs set input value Example :
<script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.descText = ''; $scope.setTextareaValue = function() { $scope.descText = "Hi Welcome to the tutorialsplane.com!"; }; }); </script> |
Html Part
Html Part contains the following html as below –
Angularjs set input value example:
<div ng-app="myApp"> <div ng-controller="myController"> <textarea name="mytext" ng-model="descText"></textarea> </br> <input type="button" ng-click="setTextareaValue()" value="Set Text" ></br> </div> </div> |
Complete Part
Now let us combine Html and JavaScript Together to create full example like this –
Angularjs set input value example
<!DOCTYPE html> <html lang="en"> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.descText = ''; $scope.setTextareaValue = function() { $scope.descText = "Hi Welcome to the tutorialsplane.com!"; }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <textarea name="mytext" ng-model="descText"></textarea> </br> <input type="button" ng-click="setTextareaValue()" value="Set Text" ></br> </div> </div> </body> </html> |
If you run the above example it will produce output something like this –
Advertisements