AngularJS 模块中的多个配置
multiple configuration in AngularJS module
我同时使用 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-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);
}());
我正在关注 ng-newsletter 文章,当我在另一个没有路由的应用程序中使用它时,它对我有用,
此外,在将此 ng-translate 配置添加到模块之前,我的路由正常工作。
可以找到我的代码的现场演示 here
你在 $translate
中有一个 space
candidatescontroller.$inject = ['$scope', '$http', 'candidatesFactory', '$timeout', 'modalService', '$location', '$anchorScroll', ' $translate'];
删除它
candidatescontroller.$inject = ['$scope', '$http', 'candidatesFactory', '$timeout', 'modalService', '$location', '$anchorScroll', '$translate'];
在您的 candidatecontroller.js 文件底部,您有一个 space 注入了“$translate”,删除 space
candidatescontroller.$inject = ['$scope', '$http', 'candidatesFactory', '$timeout', 'modalService', '$location', '$anchorScroll', '$translate'];
angular.module('ratingApp').controller('candidatescontroller', candidatescontroller);
我同时使用 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-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);
}());
我正在关注 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'];
在您的 candidatecontroller.js 文件底部,您有一个 space 注入了“$translate”,删除 space
candidatescontroller.$inject = ['$scope', '$http', 'candidatesFactory', '$timeout', 'modalService', '$location', '$anchorScroll', '$translate'];
angular.module('ratingApp').controller('candidatescontroller', candidatescontroller);