1

I have one view page with followed structure:

==============================================
| Config   |       Map        |       Charts |
===============================================
|          |                  |              | 
|          |                  |              | 

The $routeProvider for this page looks like:

var app = angular.module('cntsApp', ['ngRoute', 'ui.bootstrap','LocalStorageModule']); 

app.config(['$routeProvider', function($routeProvider) {
                $routeProvider.when('/mapboard/',
                  {templateUrl: 'app/partials/cnts.html', 
                    controller: 'CntsCtrl'});                
        }]);

cnts.html:

<div ng-include=" '/app/partials/config.html' "></div>

<div ng-include=" '/app/partials/map.html' "></div>

<div ng-include=" '/app/partials/chart.html' "></div>

All 3 HTMLs have the same scope (a.e. under one controller named 'CntsCtrl').

I want to split scope to 3 controllers.

My problem is if I'll add ng-controller for each HTML (config, map, chart) , the controllers actually will be children of CntsCtrl. And scope hierarchy will be:

rootScope 
          -> CntsCtrl
                      -> ConfigCtrl  
                      -> MapCtrl  
                      -> ChartCtrl  

But I want:

rootScope
          -> ConfigCtrl  
          -> MapCtrl  
          -> ChartCtrl  

How can I achieve that?

Thanks,

2 Answers 2

2

Simply omit controller: 'CntsCtrl' part from your route config.

ng-view directive, which is used in pair with $routeProvider, does not require source a route to have a controller.

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

Comments

1

I agree with Stewie, remove the controller part from the route, leaving just:

app.config(['$routeProvider', function($routeProvider) {
                $routeProvider.when('/mapboard/',
                  {templateUrl: 'app/partials/cnts.html'});                
}]);

And then, in your subsequent htmls you put the controller on each one:

config.html

<div ng-controller="ConfigCtrl">
    <!-- Stuff -->
</div>

map.html

<div ng-controller="MapCtrl">
    <!-- Stuff -->
</div>

chart.html

<div ng-controller="ChartCtrl">
    <!-- Stuff -->
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.