AngularJS Multiple ng-app within a page

后端 未结 13 2487
闹比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:21

    So basically as mentioned by Cherniv we need to bootstrap the modules to have multiple ng-app within the same page. Many thanks for all the inputs.

    var shoppingCartModule = angular.module("shoppingCart", [])
    shoppingCartModule.controller("ShoppingCartController",
      function($scope) {
        $scope.items = [{
          product_name: "Product 1",
          price: 50
        }, {
          product_name: "Product 2",
          price: 20
        }, {
          product_name: "Product 3",
          price: 180
        }];
        $scope.remove = function(index) {
          $scope.items.splice(index, 1);
        }
      }
    );
    var namesModule = angular.module("namesList", [])
    namesModule.controller("NamesController",
      function($scope) {
        $scope.names = [{
          username: "Nitin"
        }, {
          username: "Mukesh"
        }];
      }
    );
    angular.bootstrap(document.getElementById("App2"), ['namesList']);
    
    
    

    Your order

    {{item.product_name}} {{item.price | currency}}

    List of Names

    {{_name.username}}

提交回复
热议问题