0

I am using ng-route and ng-translate at the same time, where both require configuration in the module. Apparentely my routing is working but my ng-translate is haveing problems of being in the same confing with routing configuration.

"use strict";
(function(){
var app = angular.module('ratingApp', ['ngRoute', 'ui.bootstrap', 'ngMessages', 'ngFileUpload', 'ngAnimate', 'pascalprecht.translate']);
app.config(function($routeProvider, $translateProvider){
    $routeProvider
        .when('/', {
            templateUrl: 'views/list.html',
            controller: 'candidatescontroller'
            })
        .when('/candidate/:candiateIndex', {
            templateUrl: 'views/candiate.html',
            controller: 'candidatecontroller'
            })
    // .when('', )
        .otherwise({ redirectTo: '/'});
    $translateProvider.translations('en', {
        'TOPIC':'Candidate Poll'
            });
    $translateProvider.translations('fr', {
        'TOPIC':'Poll de Candidate'
            });
    $translateProvider.preferredLanguage('en'); 

});
}());

Here is the error that I get:

Unknown provider: $translateProvider <- $translate <-andidatescontroller

BTW: here is the end of my index.html in the term of inclduing requirements

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="js/vendor/bootstrap.min.js"></script>
    <script src="js/vendor/angular.min.js"></script>
    <script src="js/vendor/angular-translate.min.js"></script>  
    <script src="js/vendor/angular-messages.min.js"></script>
    <script src="js/vendor/angular-route.min.js"></script>
    <script src="js/vendor/ui-bootstrap-tpls.min.js"></script>
    <script src="js/vendor/ng-file-upload-shim.min.js"></script> <!-- for no html5 browsers support -->
    <script src="js/vendor/ng-file-upload.min.js"></script> 
    <script src="js/vendor/angular-animate.min.js"></script>  
    <script src="js/rateApp.js"></script>
    <script src="js/services/candidates.js"></script> 
    <script src="js/services/modal.js"></script>       
    <script src="js/candidatescontroller.js"></script>
    <script src="js/candidecontroller.js"></script>

Controller codes related to ng-tranlate:

use strict";
(function(){
var candidatescontroller = function($scope, $http, candidatesFactory, $timeout, modalService, $location, $anchorScroll, $translate){
    $scope.changeLanguage = function (key) {
            $translate.use(key);
    };
candidatescontroller.$inject = ['$scope', '$http', 'candidatesFactory', '$timeout', 'modalService', '$location', '$anchorScroll', ' $translate'];
angular.module('ratingApp').controller('candidatescontroller', candidatescontroller);
}());

I am following ng-newsletter article, and it worked for me when I used it in another app without routing,

Also, my routing was working before adding this ng-translate configurations to the module.

A live demo of my code can be found here

13
  • Have you included the reference ? Commented Nov 28, 2015 at 12:50
  • yes my friend, It's under angular.min.js and above my app <script src="js/vendor/angular-translate.min.js"></script> Commented Nov 28, 2015 at 12:52
  • can you create a plunker code or jsfiddle? Commented Nov 28, 2015 at 12:52
  • sure. yes, let me minimize the project and put the minimume there. Commented Nov 28, 2015 at 12:55
  • Post the code for this controller. Commented Nov 28, 2015 at 13:04

2 Answers 2

1

you have a space in $translate

candidatescontroller.$inject = ['$scope', '$http', 'candidatesFactory', '$timeout', 'modalService', '$location', '$anchorScroll', ' $translate'];

remove it

candidatescontroller.$inject = ['$scope', '$http', 'candidatesFactory', '$timeout', 'modalService', '$location', '$anchorScroll', '$translate'];
Sign up to request clarification or add additional context in comments.

Comments

1

Inside your candidatecontroller.js file at the bottom, you have a space injected with '$translate', remove the space

candidatescontroller.$inject = ['$scope', '$http', 'candidatesFactory', '$timeout', 'modalService', '$location', '$anchorScroll', '$translate'];
angular.module('ratingApp').controller('candidatescontroller', candidatescontroller);

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.