ng-response-converter

Shortened field names which sent by backend are being converted to original names according to specified directory.

Angular Core Dependency: ^1.4.0

Module License: MIT

Added by: S. Cahit Demir

GitHub

Repository

scahitdemir/ng-response-converter

Stats

Stars: 2

Watchers: 2

Forks: 0

Module Description

Ng-Response-Converter

This angular service, shortened field names which sent by backend are being converted to original names according to specified directory.

Download Ng-Response-Converter

You can install ng-response-converter via npm and Bower and its dependencies will be downloaded automatically:

Npm

$ npm install ng-response-converter --save

Bower

$ bower install ng-response-converter --save

Inject the Ng-Response-Converter Services

  • Add ng-response.converter.min.js to your main file (index.html).

  • Set ng-response-converter as a dependency in your module

var myapp = angular.module('myapp', ['ng-response-converter'])
  • Now the ng-response-converter services are available to be injected into any controller, service, or factory.:
app.controller("SampleCtrl", function($scope, ngResponseConverter) {
$scope._data = []; //or {}; 
// data can be object or array
    var data = [
      {
        'a': 'content of aqua',
        'b': [
          {
            'c' : {
              'e': 'content of gama'
            },
            'd' : 'content of beta'
          },
          {
            'c' : {
              'e': 'content of gama'
            },
            'd' : 'content of beta'
          }
        ]
      },
      {
        'a': 'content of aqua',
        'b': [
          {
            'c' : {
              'e': 'content of gama'
            },
            'd' : 'content of beta'
          },
          {
            'c' : {
              'e': 'content of gama'
            },
            'd' : 'content of beta'
          }
        ]
      }
    ];
//Dictionary must be like that:
    var dictionary = {
      'a': {'field': 'aqua'},
      'b': {
        'field': 'bambou',
        'object': {
          'c': {
            'field': 'alfa',
            'object': {
              'e': {'field': 'gama'}
            }
          },
          'd': {'field': 'beta'}
        }
      }
    };
  $scope._data = ngResponseConverter.change(data, dictionary);
});
  • Result
_data: [{
             'aqua': 'content of aqua',
             'bambou': [{
               'alfa': {
                 'gama': 'content of gama'
               },
               'beta': 'content of beta'
             },
             {
               'alfa': {
                  'gama': 'content of gama'
                },
                'beta': 'content of beta'
              }]
           },
           {
             'aqua': 'content of aqua',
             'bambou': [{
               'alfa': {
                 'gama': 'content of gama'
               },
               'beta': 'content of beta'
             },
             {
               'alfa': {
                  'gama': 'content of gama'
                },
                'beta': 'content of beta'
           }]

Module stats last updated: 2016-12-05 12:10:15

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!