0

I am trying to utilize ng-app with in another ng-app. Separately both ng-app's are perform their function but as they come inside each other it creates an error. for example

<body ng-app>
<div ng-app="MyApp" ng-controller="MyCtrl">
-----
</div>
<div ng-controller="ctrl">
........
</div>
</body>

On execution this give Error

Argument 'MyCtrl' is not a function, got undefined

If any one have any solution for this issue, or have some other technique to solve this problem, please help me.

2
  • Just read the documentation AngularJS applications cannot be nested within each other. Commented Jun 19, 2016 at 20:05
  • There should be any solution for this problem... If yes, then please help me. Commented Jun 20, 2016 at 7:43

2 Answers 2

1

AngularJS applications cannot be nested within each other. What you need to do is to design your modules in a way that such a thing is not needed. (eg. use nested controllers or split your app into separate modules)

Look into this topic from AngularJS website, it's explicitly mentioned that apps cannot be nested :

https://docs.angularjs.org/api/ng/directive/ngApp

To get a better sense about breaking an angular app into several modules take a look at these resources :

http://henriquat.re/modularizing-angularjs/modularizing-angular-applications/modularizing-angular-applications.html

https://www.safaribooksonline.com/blog/2014/03/27/13-step-guide-angularjs-modularization/

Sign up to request clarification or add additional context in comments.

Comments

0

There's only one ng-app allowed. There can be many modules it relies on.

Example:

//app.js
angular.module('app',['subApp'])
.run(() => { ... })

//meanwhile in subapp.js
angular.module('subapp', [])
.run(() => { ... })

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.