hello,

in my translation service when I set a new language, the observable is not 
recreated

I mean the code in the anonymous function gets not executed a second time

I tried many different things, but although the language json gets loaded 
on startup, it does not work after that

    @Injectable()
    export class TranslateService 
    {
        private trads={};
        private language="en";
    
          public translationLoaded : Observable<boolean>;
    
          private translationLoadedObserver : Observer<boolean>;
    
        constructor(private http:Http,private cookieService:CookieService ) 
        {
            this.fetchTranslation();
        }
    
        fetchTranslation()
        {
            this.getLanguage();
    
            this.translationLoaded = Observable.create((observer 
:Observer<boolean>)=> 
            {
                  this.translationLoadedObserver = observer;
    
                  this.http.get("app/translations/"+this.language+".json")
                .map(res => res.json())
                .subscribe( 
                    res => 
                    {
                        this.trads = res;
                        this.translationLoadedObserver.next(true); //add 
true to the observable
                    },
                    error =>
                    {
                        console.log(error);
                    },
                );
            }).share();
        }
    
        getTranslation = function(text:string) : string
        {
            if(this.trads[text])
                return this.trads[text];
            else
                return "<<<"+text+">>>"
        };
    
        getLanguage()
        {
                
this.language=this.cookieService.get("edenred_catalog_language");
            return this.language;
        }
    
        setLanguage(language:string)
        {
            this.language=language;
            this.cookieService.put("edenred_catalog_language",language);
            //this.translationLoadedObserver.next(false);
            //this.fetchTranslation();
            //window.location.reload();
        }
    }

regards

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" 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 https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to