Despite the fact that Everyone above answered perfectly, and I found what I was looking for, but still the working example seems to be missing.
Although understanding the automatic / manual loading in AngularJS below examples can help a lot:
AngularJS: autoload:
Angular automatically initializes / bootstraps when the DOMContentLoaded event occurs or when angular.js script is loaded into the browser, and the installation of document.readyState completes. At this point, AngularJS is looking for the ng-app directive. When the ng-app directive is found, Angular will:
Download the module associated with the directive.
Create an application injector.
Compile the DOM starting from the root ng-app element.
This process is called startup.
<html> <body ng-app="myApp"> <div ng-controller="Ctrl">Hello {{msg}}!</div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> <script> var app = angular.module('myApp', []); app.controller('Ctrl', function($scope) { $scope.msg = 'Nik'; }); </script> </body> </html>
JSFiddle: http://jsfiddle.net/nikdtu/ohrjjqws/
AngularJS - Manual Download:
You can manually initialize an Angular application using the angular.bootstrap () function. This function accepts modules as parameters and should be called inside the angular.element (document) .ready () function. The angular.element (document) .ready () function is launched when the DOM is ready to be processed.
<html> <body> <div ng-controller="Ctrl">Hello {{msg}}!</div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> <script> var app = angular.module('myApp', []); app.controller('Ctrl', function($scope) { $scope.msg = 'Nik'; }); </script> </body> </html>
JSFiddle: http://jsfiddle.net/nikdtu/umcq4wq7/
Note:
You should not use the ng-app directive when manually downloading your application.
You should not mix the automatic and manual way to download your application.
Define modules, controller, services, etc., before manually loading your application, as defined in the examples above.
Link: http://www.dotnettricks.com/books/angularjs/interview
Nikhil Maheshwari Sep 06 '15 at 5:39 on 2015-09-06 05:39
source share