AngularJS get element attributes values


AngularJS get element attributes values : We often need to add and get the custom attributes in elements. In AngularJs It’s different to get the attributes than the jQuery. Here In tutorial we are going to explain how to get custom attribute’s value in AngularJs.


AngularJS get element attributes values

You can get custom attributes as below. Here is an example –

Example : AngularJS get element attributes values

<div ng-app="myApp">  
<div ng-controller="myController">   
  
<button type="button" data-id="101" ng-click="getCustomAttr($element.target)">Get Attribute</button>
  
</div>  
</div> 
<script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
    $scope.getCustomAttr = function (item1){
    var customAttr =  angular.element(item1).data('id');
    alert(customAttr);
}
});
</script> 
</body>  

Advertisements

Add Comment

📖 Read More