AngularJS Tutorial - Create custom tag with directive








The following code shows how to Create custom tag with directive.

Example


<!--   ww  w. j  a  v a2s .  co m-->
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head>
<body>
  <div ng-app="myApp">
    <your></your>
</div>
<script type='text/javascript'>

var myApp = angular.module('myApp', []);

myApp.directive('your', function() {
    return {
        restrict: 'E',
        template: "<div> I am a directive. </div>"
    };
});
</script>
</body>
</html>

The code above is rendered as follows: