0

Controllers.js
angular.module('starter.controllers',[])

.controller('AppCtrl',function($scope,$rootScope) {
    $rootScope.side_menu = document.getElementsByTagName("ion-side-menu")[0];

 $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromParams, toParams) {
if (toState.name != 'app.map') {
    $rootScope.side_menu.style.visibility = "visible";
}
});
})
.controller('MapCtrl',function($scope) {
    $rootScope.side_menu.style.visibility = "hidden";
})

New to Angular and Ionic. Have already checked out the other questions regarding this error. Thanks.

HTML

AppJS

neilfar
  • 1
  • 3
  • Will you also paste in your html – gh9 Jun 16 '16 at 20:23
  • why are you calling your module `starter.controllers` when you use `ng-app="Starter"` – gh9 Jun 16 '16 at 20:43
  • I can remove that? – neilfar Jun 16 '16 at 20:46
  • I believe it is confused regarding which module you ar adding the controller to. Add angular.module('starter.controllers',[]) in front of your second controller or save it in a var and add it in front of every subsequent controller you will use for this module. – Zabed Akbar Jun 16 '16 at 20:46
  • I would call your module this `angular.module('starter',[])` I dont know if that is your problem but the `ng-app` directive needs to match ***Letter for letter*** whatever you call your app – gh9 Jun 16 '16 at 20:47
  • @ZabedAkbar he doesnt need to do that, he is chaining the controllers so that isnt necessary – gh9 Jun 16 '16 at 20:48
  • Something wrong with your angular module declaration. Check out the following thread http://stackoverflow.com/questions/19408011/angularjs-error-argument-firstctrl-is-not-a-function-got-undefined – Zabed Akbar Jun 16 '16 at 20:50
  • I also have an app.js file. Will it be relevant for this case? – neilfar Jun 16 '16 at 21:12

1 Answers1

1

Remove ; in app.js from the name of the controller MapCtrl.

'MapCtrl;' should be 'MapCtrl' like in example

    .state('app.map,{
      url:"/map",
      views: {
      'menuContent' :{
      templateUrl: "templates/map.html",
      controller: 'MapCtrl'
      }
     }
    })

P.S. After that you should inject $rootScope inside MapCtrl because otherwise you'll get ReferenceError: $rootScope is not defined

Tomislav Stankovic
  • 2,972
  • 9
  • 26
  • 36