AngularJS module defines an application. The module is a container for the different parts of an application. The module is a container for the application controllers.
Add a controller to your application, and refer to the controller with the ng-controller directive
Controllers always belong to a module ( ng-app ).
Example: 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<!DOCTYPE html> <html> <script src="https://code.angularjs.org/1.6.9/angular.min.js"></script> <body> <div ng-app="myApp" > <div ng-controller="myCtrl1" > <p>{{ user.height * user.weight }}</p> </div> <div ng-controller="myCtrl2" > <p>{{ user.height * user.weight }}</p> </div> </div> <script> var app = angular.module("myApp", []); app.controller("myCtrl1", function($scope) { $scope.user=[]; $scope.user.height = 5.5; $scope.user.weight = 60; }); app.controller("myCtrl2", function($scope) { $scope.user=[]; $scope.user.height = 6; $scope.user.weight = 80; }); </script> </body> </html> |
More Stories
AngularJS Dynamic Routes
Angular Demo Project
AngularJS Routes