rubenv / angular-gettext

Gettext support for Angular.js
http://angular-gettext.rocketeer.be/
MIT License
650 stars 154 forks source link

TypeError: gettextCatalog.setCurrentLanguage is not a function #364

Closed susanm74 closed 5 years ago

susanm74 commented 5 years ago

I followed this tutorial* without any issue, up until when I tried to call "gettextCatalog.setCurrentLanguage('sw')" in my $scope.changeLanguage function, which is when I get the following console error: "TypeError: gettextCatalog.setCurrentLanguage is not a function"

*tutorial originally found via this stackoverflow article

susanm74 commented 5 years ago

Ooh, so I think I figured out the issue!

this controller syntax works:

angular.module('myApp').controller('myAppController', 
   function myAppController($scope, gettextCatalog) {
   // do some stuff with gettextCatalog
});

but THIS controller syntax does NOT work:

var app = angular.module('myApp');
app.controller('myAppController', ['$scope', 'gettext', myAppController]);
function myAppController($scope, gettextCatalog) {
   // do some stuff with gettextCatalog
}

Hope this helps anyone else running into the same issue!

rubenv commented 5 years ago

app.controller('myAppController', ['$scope', 'gettext', myAppController]); function myAppController($scope, gettextCatalog) {

That's because you have a mismatch between the inject spec and what you try to use. You're injecting gettext, which is not the gettextCatalog you want.

Not a bug really, more a programmer error. Glad you figured it out!

susanm74 commented 5 years ago

Yep yep!

this controller syntax works:

var app = angular.module('myApp');
app.controller('myAppController', ['$scope', 'gettextCatalog', myAppController]);
function myAppController($scope, gettextCatalog) {
   // do some stuff with gettextCatalog
}

Thanks for the clarification!