Search code examples
jsonangularjsangular-translate

How to show translation text in angularjs controller alert from json file?


I have a JSON file with translations, like this one:

"ALERT_MESSAGE" : "Select a row"

Now, I want to show an alert from my controller when the user try to access to a link without select a row.

$scope.goToNext = function () {
    if($scope.isSelected === false){
        alert("What should I put here?");
    }
    else{
        Navigator.goTo("/next", {
            back: "/previus",
            asd: $scope.asd
        });
    }
};

How can I use my translations file on the controller?


Solution

  • Finally adding $filter to the controller and using it like here:

    alert($filter('translate')('ALERT_MSG'));