Mix buildin directive to create new directive

Description

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. j  ava 2s.  co  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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities