SoFunction
Updated on 2025-04-08

Angular method to use two ng-apps in a page (two)

In the previous article, I introduced it to youAngular method of using two ng-apps in one page, This method is not recommended. Here is a method 2. The specific code is as follows:

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <title>ng-appinstruction,angularFind the first oneng-appI won't look for it again,Use only one in a pageng-app.</title>
 </head>
 <body ng-app="myApp">
  <input type="button" ng-controller="App1Controller" ng-click="do1()" value="Button 1" />
  <input type="button" ng-controller="App2Controller" ng-click="do2()" value="Button 2">
  <script src="bower_components/angular/"></script>
  <script>
  var myApp1 = ('myApp1', []);
  ('App1Controller', ['$scope', function($scope){
   $scope.do1 = function(){
    (11111);
   };
  }]);
  var myApp2 = ('myApp2', []);
  ('App2Controller', ['$scope', function($scope){
   $scope.do2 = function(){
    (22222);
   };
  }]);
  /**
  * myApp Mod'myApp1','myApp2'ul;
  *
  * Description
  */
  ('myApp', ['myApp1','myApp2']);
  </script>
 </body>
</html>

It is to wrap two small modules with a large module.

The above is the method (2) of Angular using two ng-apps in one page introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!