JavaScript How to use TranslateHttpLoader with service url in ngx-translate

I am trying to get translated text from content management system with service URL. When I use a JSON file it works well, but how can I use a service URL to get translated data?

This is the code that's not working:

export function createTranslateLoader(http: Http) {
  return new TranslateHttpLoader(http, 'http://test.test.com/test/test/Translations/{lang}/{SiteId}');
}    
Answer:1

I ran into the same issue when trying to move from 'assets/i18n/english.json' etc to MySQL database for fetching the translated values dynamically from a table. I wanted to do this so that the admin can change them on his own.

So, I tried the answer given by Viswa and it works but I found a simpler way of doing this HttpLoaderFactory. Just add the following to your app.module.ts. Replace the URL with your API. Mine was like 'http://localhost:8080/translation/:language'

export function HttpLoaderFactory(http: HttpClient) {  
  return new TranslateHttpLoader(http, "http://localhost:8080/translation/", "");
}

Another thing that wasted some time as I was sending an array of objects like [{name: 'Name'}] instead of sending just an object like {name: 'Name'}. Once that was fixed, it worked like a charm!

Answer:2

I have an angular application, by using $stateProvider i have configured few angular states. but when i target to any state, the url appear '#' character like: http://localhost:63808/#/login, instead ...

I have an angular application, by using $stateProvider i have configured few angular states. but when i target to any state, the url appear '#' character like: http://localhost:63808/#/login, instead ...

  1. ignore synonym
  2. ignore definition
  3. ignore me
  4. ignore me meme
  5. ignore in spanish
  6. ignore antonym
  7. ignore memes
  8. ignore him
  9. ignore meaning
  10. ignore gif
  11. ignore unscramble
  12. ignore warnings python
  13. ignore her
  14. ignore me venture bros
  15. ignore case in java
  16. ignore all errors in excel
  17. ignore case python
  18. ignore quotes
  19. ignore syn
  20. ignore na in r

Please help I have done this so far. I want all 6 fiels working how can i do this? This is basically to calculate exam result so as fast help needed. function myFunction() { var a = parseFloat(...

Please help I have done this so far. I want all 6 fiels working how can i do this? This is basically to calculate exam result so as fast help needed. function myFunction() { var a = parseFloat(...

I have a mean-stack website which enables html5mode by $locationProvider.html5Mode(true). and index.html looks like as follows: <html> <head> <base href="/" /> ... </head&...

I have a mean-stack website which enables html5mode by $locationProvider.html5Mode(true). and index.html looks like as follows: <html> <head> <base href="/" /> ... </head&...

var app = angular.module('myApp', ['ui.bootstrap']); app.controller('myCtrl', function($scope,$modal){ $scope.firstName = "John"; $scope.lastName = function(){ $modal.open({ ...

var app = angular.module('myApp', ['ui.bootstrap']); app.controller('myCtrl', function($scope,$modal){ $scope.firstName = "John"; $scope.lastName = function(){ $modal.open({ ...