0

I am using angular-translate in my project but I am unable to define a controller that has a dependency injection of $translate. The code isn't executed in the browser. I checked JSHint already...

index.html

<html ng-app='ngApp'>
  <body>

    <div ng-controller="orderFormCtr">
        <ul>
            <li>{{'TITLE' | translate}}</li>
            <li translate="TITLE"></li>
        </ul>
    </div>

    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/angular-translate/angular-translate.js"></script>
    <script src="app.js"></script>

  </body>
</html>

app.js

angular.module('ngApp', ['pascalprecht.translate']);

// this code works
angular.module('ngApp').config(['$translateProvider', function ($translateProvider) {
        $translateProvider.translations('en', {
            TITLE: 'Hello'
        });
        $translateProvider.translations('de', {
            TITLE: 'Hallo'
        });
}]);

// the browser ignores this code
angular.module('ngApp').controller('orderFormCtr', ['$scope', '$translate', function ($scope, $translate) {

    alert("Controller Code executed");

}]);
4

1 回答 1

0
var app = angular.module('ngApp', ['pascalprecht.translate']);

// this code works
app.config(['$translateProvider', function ($translateProvider) {
        $translateProvider.translations('en', {
            TITLE: 'Hello'
        });
        $translateProvider.translations('de', {
            TITLE: 'Hallo'
        });
        $translateProvider.preferredLanguage('en');
        //or translateProvider.determinePreferredLanguage()
}]);

// the browser ignores this code
app.controller('orderFormCtr', ['$scope', '$translate', function ($scope, $translate) {

    alert("Controller Code executed");

}]);

http://jsbin.com/miqazola/1/

于 2014-04-17T15:44:46.667 回答