angularjs-directive Getting started with angularjs-directive Installation or Setup


Example

Directives comes with the AngularJS library itself. A sample directive can be created as:

angular.module('simpleDirective', [])
.directive('helloData', function() {
  return {
    template: 'Hello, {{data}}'
  };
});

And can be used as:

JS:

angular.module('app', ['simpleDirective'])
.controller('Controller', ['$scope', function($scope) {
  $scope.data = 'World';
}])

HTML

<div ng-controller="Controller">
  <div hello-data></div>
</div>

Will be compiled as:

Hello, World