无法设置属性翻译字典'未定义的

时间:2015-07-24 10:32:46

标签: javascript angularjs angularjs-service

我收到了许多类似的问题,但没有人与此有关。

'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

1 个答案:

答案 0 :(得分:0)

尝试:

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