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