title: Is it good to have main controller in Angular?
body: <p>I dont know if this is a good practice... I have a controller defined in route config but because my <code>HomeCtrl</code> is in <code>ng-if</code> statement he cannot listen for <code>loginSuccess</code> so I made <code>MainCtrl</code> which listens for <code>loginSuccess</code> and reacts appropriately. This code works just fine but this smells like a hack to me. Should I remove <code>MainCtrl</code> and make it a service? If so some example would be really great.</p>
  
  <p>Index.html</p>
  
  <pre><code>&lt;body ng-app="myApp" ng-controller="MainCtrl"&gt;
      &lt;div ng-if="!isLoged()"&gt;
        &lt;signIn&gt;&lt;/signIn&gt;
      &lt;/div&gt;
      &lt;div ng-if="isLoged()"&gt;
        &lt;div class="header"&gt;
            &lt;div class="nav"&gt;
              &lt;ul&gt;
                  &lt;a href="/"&gt;&lt;li class="book"&gt;navItem&lt;/li&gt;&lt;/a&gt;
              &lt;/ul&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="container" ng-view=""&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>App.js</p>
  
  <pre><code>    angular.module('myApp', [])
        .config(function ($routeProvider) {
          $routeProvider
            .when('/', {
              templateUrl: 'views/main.html',
              controller: 'HomeCtrl'
            })
            .otherwise({
              redirectTo: '/'
            });
        })
    .controller('MainCtrl', function ($scope) {
      $scope.user = false;
      $scope.isLoged = function(){
           if($scope.user){
            return true;
           }else{
            return false;
           }
      }
      $scope.$on('event:loginSuccess', function(ev, user) {
         $scope.user = user;
         $scope.$apply();
      });
    })
    .controller('HomeCtrl', function ($scope, $location) {
    //this is home controller  
    })
    .directive('signIn', function () {
      return {
        restrict: 'E',
        link: function (scope, element, attrs) {
          //go to the server and then call signinCallback();
        }
      };
    })
    .run(['$window','$rootScope','$log',function($window, $rootScope){
      $window.signinCallback = function (res) {
        if(res){
          $rootScope.$broadcast('event:loginSuccess', res);
        }
        else{
          $rootScope.$broadcast('loginFailure',res);
        }
      }; 
    }]);
  </code></pre>