0

I got the many similar questions but no one is related to this.

'use strict'
var module = angular.module('TranslationModule', []);

module.service('TranslationSevice', function (dataService, $location) {
    this.translationsDictionary;
    var getTranslationsDictionary = function () {

        return dataService('Translations?culture=' + $location.search().culture).get(function (data) {
            try {
                this.translationsDictionary = data;
            }
            catch (ex) {
                console.log('Error!', ex);
            }
        });
    }
    getTranslationsDictionary();
});

enter image description here

Romesh
  • 2,291
  • 3
  • 24
  • 47
  • possible duplicate of [How to access the correct \`this\` / context inside a callback?](http://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-context-inside-a-callback) – GillesC Jul 24 '15 at 10:35

1 Answers1

0

Try with:

return dataService('Translations?culture=' + $location.search().culture).get(function (data) {
            try {
                this.translationsDictionary = data;
            }
            catch (ex) {
                console.log('Error!', ex);
            }
        }.bind(this);
gor181
  • 1,988
  • 1
  • 14
  • 12