Multiple Module in Angularjs

后端 未结 5 1294
-上瘾入骨i
-上瘾入骨i 2020-12-02 20:26

Is it possible to create multiple module in an Angular Script? I went through the documentation and learned that it is some kind of main method concept.

I need examp

5条回答
  •  执念已碎
    2020-12-02 20:43

    Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. To run multiple applications in an HTML document you must manually bootstrap them using angular.bootstrap instead. AngularJS applications cannot be nested within each other. -- http://docs.angularjs.org/api/ng.directive:ngApp See also

    https://groups.google.com/d/msg/angular/lhbrIG5aBX4/4hYnzq2eGZwJ http://docs.angularjs.org/api/angular.bootstrap

    you can also use only one ng-app but combine 2 modules like this way:

    var moduleA = angular.module("MyModuleA", []);
    moduleA.controller("MyControllerA", function($scope) {
      $scope.name = "Bob A";
    });
    
    var moduleB = angular.module("MyModuleB", []);
    moduleB.controller("MyControllerB", function($scope) {
      $scope.name = "Steve B";
    });
    
    angular.module("CombineModule", ["MyModuleA", "MyModuleB"]);
    

    and then ng-app="CombineModule"

提交回复
热议问题