AngularJS Tutorial - Mix buildin directive to create new directive








The following code shows how to mix buildin directive to create new directive.

Example


<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
</head><!--from w  w w .  ja v  a2 s  .  c o  m-->
<body>
  <div ng-app="myApp">
    <span confirmable ng-click="doSomething()"></span>
</div>
<script type='text/javascript'>
angular.module('myApp', [])
    .run(function($rootScope) {
        $rootScope.doSomething = function() {
            console.log('hi');
        };
    })
    .directive('confirmable', function() {
        return {
            template: '<button>confirmable</button>',
            replace: true
        };
    });
</script>
</body>
</html>

The code above is rendered as follows: