JavaScript '$translate.uses(key)' undefined is not a function in AngularJS

I am trying to implement angular-translate in my application. So, I found the following JSFiddle which should demonstrate angular-translate, but I get the following error message:

'undefined' is not a function (evaluating '$translate.uses(key)')

var myApp = angular.module('myApp', ['pascalprecht.translate']);

myApp.config(function($translateProvider) {
  $translateProvider.preferredLanguage('fr');
  $translateProvider.translations('en', {
    MONDAY: 'Monday',
    TUESDAY: 'Tuesday',
    WEDNESDAY: 'Wednesday',
    THURSDAY: 'Thursday',
    FRIDAY: 'Friday',
    SATURDAY: 'Saturday',
    SUNDAY: 'Sunday'
  });
  $translateProvider.translations('fr', {
    MONDAY: 'Lundi',
    TUESDAY: 'Mardi',
    WEDNESDAY: 'Mercredi',
    THURSDAY: 'Jeudi',
    FRIDAY: 'Vendredi',
    SATURDAY: 'Samedi',
    SUNDAY: 'Dimanche'
  });
});

myApp.constant('weekDays', [{
  id: 1,
  key: 'MONDAY'
}, {
  id: 2,
  key: 'TUESDAY'
}, {
  id: 3,
  key: 'WEDNESDAY'
}, {
  id: 4,
  key: 'THURSDAY'
}, {
  id: 5,
  key: 'FRIDAY'
}, {
  id: 6,
  key: 'SATURDAY'
}, {
  id: 7,
  key: 'SUNDAY'
}]);

myApp.controller('MyCtrl', ['$scope', '$translate', 'weekDays',
  function($scope, $translate, weekDays) {

    $scope.changeLanguage = function(key) {
      $translate.uses(key)
    }
    $scope.days = weekDays;
    $scope.name = 'user';
    console.log($scope.days);
  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script src="http://rawgithub.com/PascalPrecht/bower-angular-translate/master/angular-translate.min.js"></script>

<body ng-app="myApp">
  <div ng-controller="MyCtrl">
    Hello, {{name}}!
    <div>
      <button ng-click="changeLanguage('fr')">fr</button>
      <button ng-click="changeLanguage('en')">en</button>
    </div>

    <ul>
      <li ng-repeat="day in days">
        {{ day.key | translate }}
      </li>
    </ul>

  </div>
</body>
Answer:1

$translate.uses(key) is deprecated, use $translate.use(key) instead.

Read more about angular-translate Multi Language and the 2.0.0 upgrade notification (Breaking Changes).

var myApp = angular.module('myApp', ['pascalprecht.translate']);

myApp.config(function($translateProvider) {
  $translateProvider.preferredLanguage('fr');
  $translateProvider.translations('en', {
    MONDAY: 'Monday',
    TUESDAY: 'Tuesday',
    WEDNESDAY: 'Wednesday',
    THURSDAY: 'Thursday',
    FRIDAY: 'Friday',
    SATURDAY: 'Saturday',
    SUNDAY: 'Sunday'
  });
  $translateProvider.translations('fr', {
    MONDAY: 'Lundi',
    TUESDAY: 'Mardi',
    WEDNESDAY: 'Mercredi',
    THURSDAY: 'Jeudi',
    FRIDAY: 'Vendredi',
    SATURDAY: 'Samedi',
    SUNDAY: 'Dimanche'
  });
});

myApp.constant('weekDays', [{
  id: 1,
  key: 'MONDAY'
}, {
  id: 2,
  key: 'TUESDAY'
}, {
  id: 3,
  key: 'WEDNESDAY'
}, {
  id: 4,
  key: 'THURSDAY'
}, {
  id: 5,
  key: 'FRIDAY'
}, {
  id: 6,
  key: 'SATURDAY'
}, {
  id: 7,
  key: 'SUNDAY'
}]);

myApp.controller('MyCtrl', ['$scope', '$translate', 'weekDays',
  function($scope, $translate, weekDays) {

    $scope.changeLanguage = function(key) {
      $translate.use(key)
    }
    $scope.days = weekDays;
    $scope.name = 'user';
    console.log($scope.days);
  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script src="http://rawgithub.com/PascalPrecht/bower-angular-translate/master/angular-translate.min.js"></script>

<body ng-app="myApp">
  <div ng-controller="MyCtrl">
    Hello, {{name}}!
    <div>
      <button ng-click="changeLanguage('fr')">fr</button>
      <button ng-click="changeLanguage('en')">en</button>
    </div>

    <ul>
      <li ng-repeat="day in days">
        {{ day.key | translate }}
      </li>
    </ul>

  </div>
</body>
Answer:2

On my server (written in Go), I'm sending back a custom header field that I'm trying to read from when I make an ajax call. $.ajax({ url: url, success: function(data, status, request)...

On my server (written in Go), I'm sending back a custom header field that I'm trying to read from when I make an ajax call. $.ajax({ url: url, success: function(data, status, request)...

  1. get response headers javascript
  2. get response headers
  3. get response headers angular 6
  4. get response headers curl
  5. get response headers python requests
  6. get response headers axios
  7. get response headers angular
  8. get response headers python
  9. get response headers fetch
  10. get response headers js
  11. get response headers c#
  12. get response headers php
  13. get response headers angular 7
  14. get response headers curl php
  15. get response headers java
  16. get response headers postman
  17. get response headers angular httpclient
  18. get response headers express
  19. get response headers angular 5
  20. get response headers jquery

I have one item-row.js component for each line in the CRUD and a button that triggers that "addNewItem" because I need to do some extra processing. Well, the action never bubbles up to the route, so ...

I have one item-row.js component for each line in the CRUD and a button that triggers that "addNewItem" because I need to do some extra processing. Well, the action never bubbles up to the route, so ...

I'm building dynamic drop downs for an order form for additional options. When selected these options increase the value for a dynamic amount. The drop downs are organized as such: <option value=" ...

I'm building dynamic drop downs for an order form for additional options. When selected these options increase the value for a dynamic amount. The drop downs are organized as such: <option value=" ...

  1. javascript select value from object
  2. javascript select value from dropdown
  3. javascript select value change
  4. javascript select value text
  5. javascript select value from array of objects
  6. javascript select value from array
  7. javascript select value option
  8. javascript select value selected
  9. javascript select value set
  10. javascript select value change event
  11. javascript select value onchange
  12. javascript select value null
  13. javascript select value get
  14. javascript select value undefined
  15. javascript select value of input
  16. javascript select value in input field
  17. javascript select value empty
  18. javascript select value programmatically
  19. javascript select value from json
  20. javascript select value from drop down list

Say i have conditions setup like this: if (condition1) { for (var i in objx) { if (objx[i] == 3) { //go to next else if } } } else if(condition2) { ... } so there ...

Say i have conditions setup like this: if (condition1) { for (var i in objx) { if (objx[i] == 3) { //go to next else if } } } else if(condition2) { ... } so there ...