Search code examples
javascriptangularjsng-controller

controller from another module not working


Hey so I am having a problem trying to get my child controller working. Basically I have created 2 modules in total. 1 for handling my directives and controllers for them and another to handle my gmail side of things.

//js file 
1 var gmailMod =  angular.module('gmailMod', []);

gmailMod.controller('gmailCtrl',function gmailCtrl(gmailFactory){

   this.authorize = function(){

       console.log("clicking");
       //gmailFactory.gmailAuthorize();
   }
});

//jsFile2
var emailModule = angular.module('emailMod', ['ui.bootstrap']);

I have a third file called config that declares the dependencies

angular.module('seamysApp', ['ngRoute', 'emailMod', 'gmailMod'])

So anyways the email Mod works perfectly but when I try to declare a child controller on my button form the gmailMod

<div ng-controller="gmailCtrl">
  <button ng-click="authorize()" class="btn-info" >Not authorized yet! Click here! :)</button>
</div>

Nothing works. I can't get the authorize function to work. Why is this happening does anyone know? I'm getting no errors in my console so I think it must be some logical error by me and it's difficult to find. Thanks in advance for the help.


Solution

  • <div ng-controller="gmailCtrl as gCtrl"> <button ng-click="gCtrl.authorize()" class="btn-info" >Not authorized yet! Click here! :)</button> </div>