gpt4 book ai didi

javascript - AngularJS 模块中的多重配置

转载 作者:行者123 更新时间:2023-12-02 15:21:58 25 4
gpt4 key购买 nike

我同时使用 ng-route 和 ng-translate,两者都需要在模块中进行配置。显然我的路由工作正常,但我的 ng-translate 存在与路由配置处于同一配置中的问题。

"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');

});
}());

这是我收到的错误:

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

顺便说一句:这是我的index.html 的结尾,包含了要求

    <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>

与ng-translate相关的 Controller 代码:

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);
}());

我正在关注ng-newsletter文章,当我在另一个应用程序中使用它而无需路由时,它对我有用,

此外,在将此 ng-translate 配置添加到模块之前,我的路由正在运行。

可以找到我的代码的实时演示 here

最佳答案

您在$translate中有一个空格

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

删除它

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

关于javascript - AngularJS 模块中的多重配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33971500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com