angularjs - Translating during config phase (using angular-translate) -


i'm developing i18n part of angular web app, , i'd use angular-translate in config phase.

i defined data i'd translate:

.state('app.tracking', {     url: '/:identityidentifier',     params:{         identityidentifier: {squash: false, value: null}     },     templateurl: 'views/pages/tracking.html',     data : { title: $filter('translate')('tracking.tracking.title') },     resolve: load([], function(){ return loadgooglemaps(); }) }) 

here's config declaration:

.config(   [          '$stateprovider', '$urlrouterprovider', '$locationprovider', 'module_config', '$httpprovider', '$filter',     function ($stateprovider,   $urlrouterprovider,   $locationprovider,   module_config,   $httpprovider,   $filter) { 

the error classic: error: [$injector:unpr] unknown provider: $filter

i'm aware can't use services in config phase, providers, there solution problem?

edit: problem has been solved assigning key 'tracking.tracking.title' data.title variable, translating using translate directive in markup.

yes, mentioned in edit question: applying filter in markup easiest solution.

besides that, if 1 want access services in config phase, read on:

it technically not possible in angular <= 1.4.

starting angular v1.5 (current rc version 1.5.0-rc.0) seems possible, although cannot recommend so, because config phase should place services configured before they're used first time.

this change made following possible (link angular.js repo @ github) (it made allow decorating $injector).

now, here comes example: http://codepen.io/nicbright/pen/pzjbpp?editors=101

js part:

(function() {   var result;  angular.module('myapp', [])   .config(function($injectorprovider) {     result = $injectorprovider.$get().get('myservice').getsomething();   })   .factory('myservice', function() {     return { getsomething: function() { return 'it works!'; }}   })   .controller("mainctrl", function($scope) {     $scope.result = result;   })  })(); 

html part:

<div ng-app="myapp" ng-controller="mainctrl">   result: {{ result }} </div> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -