Wednesday 19 June 2013

ngApp in AngularJs

AngularJS applications need to be 'bootstrapped.' This is done by adding the ng-app directive to an element in the page. You can use any element but typically the root 'body' or 'html' element is used.

<html ng-app="">
</html>

Notice that hg-app takes a string value, this is the name of a module to load, if you have no modules this can be the empty string.

Once you have this in place you can then start using Angular

<html ng-app="">
<body>

{{3 + 34}}
</body> </html>

will cause angular to 'execute' the template and display the value 37 on the page.

This is about as simple as it gets for Angular code.

The problem with the simple approach of just using ng-app is that this is not compliant with the HTML 5 specification. Because of this Angular provides other ways of defining directives. Instead of just ng-app, you could use data-ng-app (this is the most widely used alternative) x-ng-app. This applies to all the directives not just ngApp.

1 comment:

  1. I missed some topics on the subject when attending online Angularjs training center. However, I found all those concepts on this blog well presented. Thanks .

    ReplyDelete