AngularJs Modules : AngularJs Modules works as container for controllers. Controllers are associated with modules.
Example for AngularJs Modules
Let us understand with the following example.
We have created an application named as “myApp” which have the controller named as “myController”.
<div ng-app="myApp"> <div ng-controller="myController"> Name : Name : Name : {{ name }} Email : {{ email }} </div> </div>
Now let us create module
AngularJs Modules Full Example
Example
<div ng-app="myApp"> <div ng-controller="myController"> Name : Name : Name : {{ name }} Email : {{ email }} </div> </div> |
Output :
Note : You can keep your module and controller javaScript code in external js file. Example module.js and controller.js. Include these file such as
Example
myApp.js will have following code.
var myApp = angular.module("myApp", []);
myController.js will have following code.
myApp.controller("myController", function($scope) { $scope.name = "Tani"; $scope.email = "tanib@yopemail.com"; });