Tuesday, June 3, 2014

Creating Reusable Directive in AngularJS


Code snippet for creating Reusable directive in AngularJS

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en" ng-app="APP">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Custom Tag Example</title>
</head>
<body>
<name first="Amit" last="Sharma"></name>
<script src="script/angular.min.js"></script>
<script>
var APP=angular.module('APP',[]);
APP.directive('name',function(){
return{
restrict:'E',
link:function(scope,e,a){
scope.fullname = a.first+' '+a.last
},
replace:true,
template:"<h1>{{fullname}}</h1>"
}
});
</script>
</body>
</html>

No comments:

Post a Comment