Hi NagaSrinivas Medicherla.

I think the error is occurring because your factory is not returning a 
promise, that's why the error says "Cannot read property 'then' of undefined
".
You need to *return deferred.promise;* and *resolve* or *reject* inside the 
functions that you pass to the "*RestServiceCall*" function.

I hope this helps.

Regards,
*Luís Loureiro*

quinta-feira, 2 de Julho de 2015 às 18:36:19 UTC+1, NagaSrinivas Medicherla 
escreveu:
>
> Hi every one,
>
> My requirement is load the localization data dynamically(need to lad the 
> data from WEB API service), So I am using the $translateProvider in 
> app.config and calling app.factory in  useLoader method , the code is below 
>   . I am getting error like  angular.js:3831 Uncaught TypeError: Cannot 
> read property 'then' of undefined
>
> Can you please help me on this
>
>
> var app = angular.module('IRISapp', ['ngRoute', 'pascalprecht.translate']);
>         
>     app.config(['$routeProvider', '$translateProvider', '$httpProvider', 
> function ($routeProvider, $translateProvider, $httpProvider) {
>        
>             
> $translateProvider.useLoader('CustomLoader').preferredLanguage('EN');
>         $translateProvider.useSanitizeValueStrategy(null);
>         $translateProvider.fallbackLanguage(['FR', 'EN']);
>
>
>        
>     }]);
>
> app.factory('CustomLoader', function ($http, $q, RestServiceCall, 
> EndpointsFactory, $rootScope) {
>         var customLoader = {};
>         return (function (options) {
>             
>             var ct = this;
>             
>             var data = {
>                 'TEXT': 'Fooooo'
>             };
>             var deferred = $q.defer();
>             // do something with $http, $q and key to load localization 
> files
>             $rootScope.transalatedata = function () {
>                 EndpointsFactory("GetLanguage", null, ct.localdata);
>             };
>             ct.localdata = function (restUrl) {
>                 RestServiceCall('POST', restUrl, null,
>                   // success
>                       function (response) {
>                           
>                           data = response;
>                                                  
>                          
>                           // $translateProvider.translations('EN', 
> response)
>                           //alert(responseresponse
>                       },
>                   // error
>                    function (data, status, headers, config) {
>                        console.log(data);
>                        //this.message = status;
>                    }
>               );
>             };
>             $rootScope.transalatedata();
>             alert('before deferred  data is' + data);
>            // data = options;
>             return deferred.resolve(data);
>             alert('after deferred  data is' + data);
>             // or
>             return deferred.reject(options.key);
>         });
>        
>     });
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to