خرید بک لینک

Vote count: 0

I have this service:

.factory('LocalizationService', ['$resource', function ($resource) {

    // Create our service
    var LocalizationService = function (language) {

        // Get a reference to this service
        var self = this;

        // Use default if no language is supplied
        language = language || 'en_EU';

        // Get the path of the json
        var path = '/assets/resources/' + language + '/resource.json';

        // Retu our promise
        $resource(path).get(function (response) {

            // Assign our response to our service
            self.resource = response;
        });
    };

    // Retu our service
    retu LocalizationService;
}])

and to instantiate it I would have to call

var localazation = new LocalizationService();

but I would like to use it as normal, so that it behaves like all other services. I have a validation function that has something like this in it:

// If we have no sport
if (!team.sport) {

    // Display a waing
    errorMessage = errorMessage ? errorMessage + '<br />' + service.localization.sportInvalid.message : service.localization.sportInvalid.message;
}

// If no team name has been set
if (!team.name) {

    // Display a waing
    errorMessage = errorMessage ? errorMessage + '<br />' + service.localization.teamInvalid.message : service.localization.teamInvalid.message;
}

// If no colours have been chosen
if (!team.colour1 || !team.colour2) {

    // Display a waing
    errorMessage = errorMessage ? errorMessage + '<br />' + service.localization.colourInvalid.message : service.localization.colourInvalid.message;
}

now, using the instantiation above would be fine. But if I have my localization service used elsewhere (as I do) I need to make sure that both are using the same language and that someone doesn't accidentally specify something else. If it was a singleton and worked like other services I would be fine. Does anyone know how I can achieve what I am after?

asked 2 mins ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 3 اسفند 1394 ساعت: 0:47

صفحه بندی