AngularJS Multiple ng-app within a page

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

             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"
                 }];
               }
             );
    
    
             var namesModule = angular.module("namesList2", [])
              namesModule.controller("NamesController",
               function($scope) {
                 $scope.names = [{
                   username: "Nitin"
                 }, {
                   username: "Mukesh"
                 }];
               }
             );
    
    
             angular.element(document).ready(function() {
               angular.bootstrap(document.getElementById("App2"), ['namesList']);
               angular.bootstrap(document.getElementById("App3"), ['namesList2']);
             });
    
    
    
    
      
    
    
    
    
    
      

    Your order

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

    List of Names

    {{_name.username}}

    List of Names

    {{_name.username}}

提交回复
热议问题