bootstrap to use multiple ng-app

后端 未结 1 854
闹比i
闹比i 2021-01-21 20:18

I followed the code in AngularJS Multiple ng-app within a page

I don\'t know what i\'m missing.

    var reviewApp = angular.module(\"reviewApp\", []);
va         


        
1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 20:47

    When you are bootstrapping multiple apps, you can not use ng-app attribute more than once, angular takes the first one in markup and bootstraps it automatically, all the other ng-apps are ignored and you have to bootstrap them manually

    var reviewApp = angular.module("reviewApp", []);
    var reviewApp2 = angular.module("reviewApp2", []);
    
    reviewApp.controller("reviewCtrl",
                         function ShippingAddressCtrl($scope, $http) {
        $scope.name='leo1';
    });
    
    reviewApp2.controller("productController",
                         function ProductController($scope, $http) {
        $scope.name1='leo2';
    });
    angular.element(document).ready(function() {
        angular.bootstrap(document.getElementById("div1"),['reviewApp']);
        angular.bootstrap(document.getElementById("div2"),['reviewApp2']);
    });
    

    html

    {{name}}
    {{name1}}

    0 讨论(0)
提交回复
热议问题