Wednesday, September 6, 2017

How to access jQLite or jQuery with AngularJS? OR What is angular.element() in AngularJS?

jQuery lite or the full jQuery library if available, can be accessed via the AngularJS code by using the element() function in AngularJS. Basically, angular.element() is an alias for the jQuery function i.e.


angular.element() === jQuery() === $()

For Example:


<html>
<head>
<script src="lib/angular.js"></script>

<script type="text/javascript">
var app = angular.module('app', []);

app.controller("mainCtrl", function ($scope, $element) { $scope.clickme = function () {

var elem = angular.element(document.querySelector('#txtName')); console.log(elem.val())// console the value of textbox

};
});
</script>

</head>
<body ng-app="app">
<div ng-controller="mainCtrl">

<input type="text" id="txtName" value="Shailendra Chauhan" /> <button type="button" ng-click="clickme()">Click me</button>

</div>

</body>
</html>




No comments:

Post a Comment

What is restrict option in directive?

The restrict option in angular directive, is used to specify how a directive will be invoked in your angular app i.e. as an attribute, class...