Angularjs one or more ng apps?

I am working on a web application. It is protected by Spring from controllers to the database. I am currently processing page navigation using Spring MVC's accessor methods for accessing pages.

I plan to use angular JS to execute my user interface. I was looking for examples on how to do this, and all this is good, but I'm not sure about something ...

ng app

1- Should I use one for each application or one on the page, or does it not matter?

2- If it does not matter, when should I decide?

I see examples using it in the html tag, and some others use it in the div, but I'm not sure how to solve it, possibly due to a lack of understanding of the structure.

+4
source share
3 answers

angular docs

Only one AngularJS application can be automatically loaded per HTML document. The first ngAppone found in the document will be used to determine the root element for automatic loading as an application. To run multiple applications in an HTML document, you must manually download them using angular.bootstrap instead. AngularJS applications cannot be nested within each other.

You can define several modules that may have dependencies between them.

angular.module('Core', []);
angular.module('Module1', ['Core']);
angular.module('Module2', ['Core']);

Use the appropriate module on each page. How many modules should you have? It depends on how complex your application is and how you structure it.

, angular, , . . , , angular, .

, .

:

, , ng-app ( , , , )

+4

1- , ?

, , angular , ng-, ,

, /

2- , ?

  • Angular , , - , .
  • , , - , , .
  • angular MVC - , , . jsp thymrleaf, REST ( RESTful, $resource) api spring
  • , javascript, / . .
  • , , angular, , //stackoverflow. , .
+6

2 , , , , . .

/ factory, /, , - ng-, . , , , 2 30 , , 10 , . ( , ). , , 2 .

Update:

There is a fix using the UI route from the angular user interface that handles this loading problem pretty well (time drops to 20% of the original), and also helps to split the page into 2 applications, as I said at the beginning minus the need to literally split the page into 2. Nevertheless, I do not see any good examples for this practice, although, especially with a handheld device, this only makes the page more complex.

-one
source

All Articles