0

I am new to Angular.js and want to use one ng-controller within another ng-app and ng-controller like this so that I will be able to use the code before I used on the other pages as well. Please help me out and correct me if I am wrong anywhere.

<div id="divFriendList" class="container" ng-app="friendModule" ng-controller="friendController">
    <div id="module2" ng-app="cardsModule" ng-controller="CardsController">
        <div ng-repeat="card in cards></div>
    </div>
</div>
ghost_dad
  • 1,308
  • 2
  • 12
  • 21
Manisha Agarwal
  • 101
  • 1
  • 3
  • 10

1 Answers1

0

I am rather new as well, but I believe a way to do this would be to declare a dependency in your module. For example, angular.module('friendModule', ['cardsModule']);. Such an example can be found here. For more about modules and a tutorial on angular you can visit W3Schools.

As for your code, you're missing the closing quotation in <div ng-repeat="card in cards>. Further, you are asking ng-repeat to iterate each card in cards, but you have not defined what cards is. Therefore, you'll want to change

<div id="module2" ng-app="cardsModule" ng-controller="CardsController">

to

<div id="module2" ng-app="cardsModule" ng-controller="CardsController as cards">.

Additionally, you will not get any information displayed if you don't ask for an output such as {{card}}. I would also consider declaring your ng-apps before hand and not when they're needed - but I'm unsure as to the efficiency of this.

What I would update as:

 <div id="divFriendList" class="container" ng-app="friendModule" ng-controller="friendController">
     <div id="module2" ng-app="cardsModule" ng-controller="CardsController as cards">
         <div ng-repeat="card in cards">{{ card }}</div>
     </div>
 </div>

Hope that helps.

Community
  • 1
  • 1
gehleh
  • 1,191
  • 1
  • 8
  • 5
  • Thanks It worked fine for me but I am getting this error Uncaught Error: [$rootScope:infdig] when I click on any link.Please help me out to resolve that – Manisha Agarwal Dec 23 '14 at 10:51
  • As I said, I'm a newbie as well so I'm unsure what it could be, but these might help: http://stackoverflow.com/questions/26723927/angularjs-uncaught-error-rootscopeinfdig-10-digest-iterations-reached and http://stackoverflow.com/questions/25103966/uncaught-error-rootscopeinfdig-in-browser-console-when-implementing-a-elaps – gehleh Dec 23 '14 at 20:00