Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap to use multiple ng-app

Tags:

angularjs

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", []);
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.bootstrap(document.getElementById("div2"),['reviewApp2']);

http://jsfiddle.net/lordango/X3ZsU/1/

like image 754
lordango Avatar asked May 15 '26 16:05

lordango


1 Answers

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

<div id="div1">
<div ng-controller="reviewCtrl">{{name}}</div>
</div>

<div id="div2">
<div ng-controller="productController">{{name1}}</div>
</div>
like image 155
doodeec Avatar answered May 17 '26 20:05

doodeec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!