-1

I am new to AngularJS. I'd like to know what is the difference if I place ng-app in either <html> tag or <body> or <div>. Similarly same doubt for ng-controller .

Roman C
  • 49,761
  • 33
  • 66
  • 176
Ritesh Gupta
  • 171
  • 1
  • 2
  • 19
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. – Roman C Oct 22 '16 at 12:08

2 Answers2

0

Where ever you put ng-app the elements inside it can only access the module and ng-controller can be used only when you have used ng-app in some upper element...

The controllers are accessible only if the module is initialised which is done using ng-app statement..

remember that the mmodule needs to be initialised only once and on an element under which you want all the angular controllers functionality for your various elements

Pankaj Kumar
  • 871
  • 5
  • 12
0

The positioning of tag ng-controller defines the visibility and usage of scope

<div ng-controller="outerController" id="outerController">
    //outerController $scope is available here
    //innerController $scope is **not** available here

    <div ng-controller="innerController" id="innerController">
        //outerController $scope is available here
        //myControllers $scope is available here
    </div>
</div>

Nested controllers will search for elements on the closest bound scope first before ascending the chain.

For example imagine $scope.outerVar is set on the outerController

If innerController attempts to access $scope.outerVar then a check is done to see if this property is set on the innerController first. Only if it is not set will it go up the chain to outerController to retrieve it from there.

Revive
  • 2,248
  • 1
  • 16
  • 23