9673

bootstrap to use multiple ng-app

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/

Answer1:

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>

Recommend

  • SELECT random users from MySQL in one row
  • Dynamically generated CURSOR in Postgresql
  • How to sort date strings (format example: 2014 7 23) in JavaScript?
  • typeid result across different dll's
  • NSSortDescriptor not being called
  • oracle sql pivot query table
  • Struts 2 : Passing array of String as static param
  • plsql procedure to compare two tables where structure of table is not known
  • .val() not getting updated value from input
  • TableViewCell to auto-resize its height according to content in xcode?
  • Parsing a tab delimited text file with VB.Net
  • pulling the list of values from the list of keys
  • Richfaces editable dataTable not setting updated values in Bean
  • How to loop on Python 3.4.2? [duplicate]
  • Elasticsearch - query primary and secondary attribute with different terms
  • jqGrid: Combining sortableRows and gridDnD (Duplicate Rows)
  • MySQL 'if exists' error
  • Using C# Attributes and documentation
  • Storing data from SQL in array
  • keeping track of nested ng-repeat index's
  • How to save dynamically created textboxes and their values
  • Using an STL Iterator without initialising it
  • How do I remove all but some records based on a threshold?
  • Using $compile in a directive triggers AngularJS infinite digest error
  • Updating Dojo provide
  • ASP.NET MVC Application won't update some controllers
  • CakePHP ACL tutorial initDB function warnings
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Is it possible to access block's scope in method?
  • Python - Map / Reduce - How do I read JSON specific field in using DISCO count words example
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?