Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

46
Views
How to call transformResponse many times in Angularjs

I need to call transformResponse many times based persons array. But the following code call only the last index

function fill() {
            var persons = [
                { id: 34, text: $translate.instant("enter") },
                { id: 36, text: $translate.instant("high") },
                { id: 53, text: $translate.instant("graduates") },
                { id: 35, text: $translate.instant("persons") },
            ]
            var personSubCategoriesList = [];
            for (var i = 0; i < persons.length; i++) {
                $scope.remote = {
                    url: window.config.apiHostUrl + `lookup/Get?id=${persons[i].id}`,
                    transformResponse: function (data) {
                        var personSubCategories = angular.fromJson(data);
                        angular.forEach(personSubCategories, function (personSubCategoriesObjet) {
                            var categories = { name: personSubCategoriesObjet.localizedName, code: personSubCategoriesObjet.id };
                            personSubCategoriesList.push(categories);
                        });
                        return personSubCategoriesList.map(function (adminCategories) {
                            return {
                                name: adminCategories.name,
                                code: adminCategories.code
                            };
                        });
                    }
                };
            }
        }
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

I found the solution by using observable $q

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs