Answer the question
In order to leave comments, you need to log in
How to feed Angular dynamic data from Ajax.jquery?
Actually, in the process of creating localization on angular, I encountered the following problem:
During validation and user actions, the server responds via ajax
var ajaxSettings = {
type: method,
url: action,
data: $form.serialize()
};
var app = angular.module('translation', ['ngResource','ngCookies']);
app.controller('language', ['$scope', '$cookies', 'translationService',
function ($scope, $cookies, translationService) {
//Выполняем перевод, если произошло событие смены языка
$scope.translate = function (langKey) {
translationService.getTranslation($scope, langKey);
$cookies.loc_language = langKey;
};
var $cur_lang = $cookies.loc_language;
if ($cur_lang == null) {
$scope.translate('ru');
} else {
$scope.translate($cur_lang);
}
}]);
app.service('translationService', function ($resource) {
this.getTranslation = function ($scope, language) {
var languageFilePath = 'lang/translation_' + language + '.json';
console.log(languageFilePath);
$resource(languageFilePath).get(function (data) {
$scope.translation = data;
});
};
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question