2

I have a page in that header and footer part is the common and view part is different.

The code I written for the index.html page is:

<html lang="en" data-ng-app="dashboard">

<head>  
 <!-- All the Libraries & css--> 
</head>

<body>
<header>  </header>

<data-ng-view>  </data-ng-view>

<footer>   </footer>

</body>
</html>

For data-ng-view, in the homepage I have 3 divs each div have it's own controller.

Main controller is like:

var app = angular.module('dashboard', ['ngRoute'])
    .config(['$routeProvider', function($routeProvider) {
      $routeProvider.
      when('/records', 
              {
                templateUrl: 'view/homepage.html', 
                controller: 'RecordsController'
                }
      ). otherwise({redirectTo: '/records'});  
  }]);

Here is the structure for the homepage.html

<div id='main'>
    <article>           
        <div ng-controller="FlipDemoCtrl"> 
            <!-- contents to display -->
            </div>
    </article>
    <nav>
        <div ng-controller="HomePageLinks">  
            <!--  contents to display -->
            </div>
        <hr>
        <ul ng-controller="ResolveProblem">
        <!-- list of contents through ng-repeat -->             
        </ul>
        <hr>
    </nav>
</div>

My question is:

How should I define the RecordsController so that through this controller I am able to call the FlipDemoCtrl, ResolveProblem & HomePageLinks Controller.

function RecordsController($scope, $http) {

 // How should I write this function to call the multiple controllers

}
SW4
  • 69,876
  • 20
  • 132
  • 137
Vaibhav Jain
  • 3,729
  • 3
  • 25
  • 42
  • There are a couple of way to achieve the goal: events broadcasting, *uber*-controller, common shared `service`. I would probably use the last of these three in your case. – artur grzesiak Apr 29 '14 at 09:47
  • @arturgrzesiak: Ok. Please provide any useful link for creating service or better provide me syntax for the service in my case. – Vaibhav Jain Apr 29 '14 at 09:54
  • 1
    @VaibhavJain : See this link, you can broadcast events from parent to child. http://stackoverflow.com/questions/19038778/angularjs-how-to-call-child-scope-function-in-parent-scope – Ritesh Waghela Apr 29 '14 at 10:00

1 Answers1

0

Use a Service to share common logic between Controllers. Then injecting the service into the four controllers, you can access the common data.

Ametzaga
  • 140
  • 7
  • 15
  • Is it applicable for only common data ? In my case all the three controllers have different data. Apart from service is there any other way to Call the controller ? If No can you please provide some kind of syntax for my case. – Vaibhav Jain Apr 29 '14 at 12:22