Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm developing my first AngularJS app.

master.html is the shell/main page which will load child pages and has it's own logic (i.e. users, search, etc).

The following image shows conceptual structure of my project-

enter image description here

My app.js -

var myApp= angular.module('myApp', ['ngRoute', 'ngResource']);

myApp.config(function ($routeProvider, $locationProvider) {

$routeProvider.when('/',
    {
        templateUrl: '/app/views/blogslist.html'
        controller: 'BlogListController'
    })
});

I want a controller for master.html also. I know I can use ng-controller anywhere. But How and where I'll configure the controller for this page?

Thanks.

share|improve this question
    
I want a controller for master.html.....may be a silly question, but why? –  Jai Nov 12 '14 at 6:21
    
@Jai Surely this could be silly, because i am learning it. Read the question carefully. Anyway, do you have any suggestion? –  s.k.paul Nov 12 '14 at 6:24
1  
You can use the ng-controller directive on any element on master.html. –  Anthony Chu Nov 12 '14 at 6:25
    
actually my question why? is silly not yours. and agreed with AnthonyChu –  Jai Nov 12 '14 at 6:25
    
@SKPaul As Anthony suggested you can use ng-controller but why do you need this controller? There may be better options based on your needs. –  skusunam Nov 12 '14 at 6:29

2 Answers 2

up vote 1 down vote accepted

May be you are looking for something like this:

var myApp= angular.module('myApp', ['ngRoute', 'ngResource']);

myApp.controller('masterCtrl', ['$scope', function($scope){
   // all your logic here
}]);

myApp.config(function ($routeProvider, $locationProvider) {
    .........    
});

and you can use ng-controller attribute to the wrapper div or body.

share|improve this answer
    
You are very close to my question. Do I simply need to place the masterCtrl.js file on master.html? or, tell it in myApp.config(...)? I have ambiguity here. –  s.k.paul Nov 12 '14 at 6:39
    
for sake of simplicity you can use a separate js file. –  Jai Nov 12 '14 at 6:42

Use Angular UI Router instead of ngRoute. It allows nested views and states - exactly what you need here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.