angular-element-2

 

In this example of angular element, we have a textbox and value of this text box is set with the help of angular.element on clicking the button. See the code snippet:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="elementController"> <input type="text" id="myText" ng-model="myVal" /> <button ng-click="getVal()">Get Val</button><br /> {{value}} </div> <script> var app = angular.module("app", []); app.controller('elementController', ['$scope', '$document', function ($scope, $document) { $scope.myVal = "LearnKode"; $scope.getVal = function () { $scope.value = angular.element($document[0].querySelector('#myText')).val(); } }]); </script> </body> </html>
Output