2AngularJS - AdditionalReferences1
2AngularJS - AdditionalReferences1
2AngularJS - AdditionalReferences1
Additional References:
f
Ans-1:
The second would be to bootstrap from the JavaScript, like so, after having
creating your app through angular.module("myApp", []);
angular.bootstrap(document, ['myApp']);
Ans-2:
Though Everyone above has answered perfectly and I found what I was looking
for but still a working example seem missing.
<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/
<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';
});
//manual bootstrap process
angular.element(document).ready(function () { angular.bootstrap(document,
['myApp']); });
</script>
</body>
</html>
JSFiddle : http://jsfiddle.net/nikdtu/umcq4wq7/
Note :
1. You should not use the ng-app directive when manually bootstrapping
your app.
2. You should not mix up the automatic and manual way of bootstrapping
your app.
3. Define modules, controller, services etc. before manually bootstrapping
your app as defined in above examples.
Reference : http://www.dotnettricks.com/books/angularjs/interview
Ans-3:
Adding to Dave Swersky's answer (and I'm new to Angular so correct me if I'm
wrong):
The following image, taken from the angularjs.org bootstrap tutorial. Explains
what Dave articulated.
The HTML, inside the element with the ng-app directive, is compiled by
AngularJS. For example:
<body>
<div> {{ 1 + 2 }} </div>
</body>
This is because the ng-app "bootstrapped" the body tag and told Angular to
create an "internal representation" of the content. The internal representation
is, of course, 3. From the tutorial:
"If the ng-app directive is found then Angular will compile the DOM
treating the ng-app directive as the root of the compilation. This allows
you to tell it to treat only a portion of the DOM as an Angular application."
Angular also loads the module associated with the ng-app directive ("module"
in the Angular tutorial) and creates an application injector (used for
dependency injection).