Module in angular

AngularJS modules are containers. It just like namespace in C#. They separate an angular app into medium or large reusable components which can be integrated with other angular application.

Example

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

app.directive('myDirective', function() {
   var directive = {};
   directive.restrict = 'A';
   directive.template = "<h4>Using Directive from injected module</h4>";
   return directive;
});

app.controller('secondCtrl', function($scope) {
  $scope.name = 'Using Controller from injected module';
});

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

MainApp.controller('MainCtrl', function($scope) {
  $scope.name = 'Original Module';
});
HTML
<html ng-app="MainApp">
  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <p my-directive>sdf</p>
  </body>

  <div ng-controller="secondCtrl">
    {{name}}
  </div>
</html>

-->

results matching ""

    No results matching ""