multiple configuration in AngularJS module
Asked Answered
C

2

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

Cyna answered 28/11, 2015 at 12:50 Comment(13)
Have you included the reference ?Sherrillsherrington
yes my friend, It's under angular.min.js and above my app <script src="js/vendor/angular-translate.min.js"></script>Cyna
can you create a plunker code or jsfiddle?Sherrillsherrington
sure. yes, let me minimize the project and put the minimume there.Cyna
Post the code for this controller.Cowans
@dfsq: I updated the post in the term of contoller.Cyna
@Sherrillsherrington plunker code is here:plnkr.co/edit/7jFrXj0v0CL8A3Byhyyy?p=previewCyna
@Cowans plunker codes is here: plnkr.co/edit/7jFrXj0v0CL8A3Byhyyy?p=previewCyna
I don't see the same error on your plunker, some of the references are not loadingSherrillsherrington
@Sherrillsherrington the only difference is I removed the path in front of refrences since I cant make directories there., and the whole codes are pasted the files.Cyna
@Sherrillsherrington See the route is working but {{ 'TOPIC' | translate }} which ng-traslate is not workingCyna
@AliSaberi Save your plunkr code, so other people can see your changes.Amphictyon
@BabajideFowotade DONECyna
K
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'];
Korrie answered 28/11, 2015 at 13:47 Comment(0)
A
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);
Amphictyon answered 28/11, 2015 at 13:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.