2

I am using ng-show with a custom function. This function calls '$translate.use'-method inside the controller.

Funny enough, this works for the main-page but not for all other controllers although all of them use the same peace of code.

The console tells me that $translate is undefined.

Here's my peace of code for the index-page:

app.controller('LangCtrl', function ($scope, $translate) {

    $scope.isenglish = function () {
        if ($translate.use() == 'en_US') {
            return true;
        }
        return false;
    }........

and for another controller:

app.controller('selectFormController', ['$scope', '$http', 'storage', '$rootScope', function ($scope, $http, storage, $rootScope, $translate) {

........

  $scope.isenglish = function () {
        if ($translate.use() == 'en_US') {
            return true;
        }
        return false;
    }

I am really puzzled - is anybody able to help me out?

Thanks a lot!!! Steffen

1
  • I guess you have a typo.. app.controller('selectFormController', ['$scope', '$http', 'storage', '$rootScope', function ($scope, $http, storage, $rootScope, $translate) { should be app.controller('selectFormController', ['$scope', '$http', 'storage', '$rootScope',' $translate', function ($scope, $http, storage, $rootScope, $translate) { Commented May 28, 2015 at 14:44

2 Answers 2

3

It seems that you're not really injecting $translate, check this out:

app.controller('selectFormController', ['$scope', '$http', 'storage', '$rootScope', '$translate', function ($scope, $http, storage, $rootScope, $translate)

Mind the $translate after $rootScope

Sign up to request clarification or add additional context in comments.

1 Comment

embarassing... ;-) THANK YOU
3

Its working in LangCtrl controller because you directly injecting $translate dependency. But in your selectFormController controller you are using inline array annotation you need to add dependency in array as string(dependency name) first and then you could use it inside the controller function

In short you missed to add $translate dependency in your selectFormController controller.

Code

app.controller('selectFormController', ['$scope', '$http', 'storage', '$rootScope', '$translate', 
function ($scope, $http, storage, $rootScope, $translate) {

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.