AngularJS Multiple ng-app within a page

后端 未结 13 2230
闹比i
闹比i 2020-11-22 01:48

I have just started learning Angular JS and created some basic samples however I am stuck with the following problem.

I have created 2 modules and 2 controllers.

13条回答
  •  遥遥无期
    2020-11-22 02:30

    To run multiple applications in an HTML document you must manually bootstrap them using angular.bootstrap()

    HTML

    
    
    ...
    ...

    JS

    angular.
      bootstrap(document.getElementById("module2"), ['mySecondModule']);
    

    The reason for this is that only one AngularJS application can be automatically bootstrapped per HTML document. The first ng-app found in the document will be used to define the root element to auto-bootstrap as an application.

    In other words, while it is technically possible to have several applications per page, only one ng-app directive will be automatically instantiated and initialized by the Angular framework.

提交回复
热议问题