Adding the input fields dynamically from nested json object in angulajs

Deepak Pookkote
 var inputs={
    'firstname': '',
    'lastName':'',
   'account':{
     'role':'',
     'status':''
   }
 }

This is my model array. I want to display it dynamically in Webpage and by modifying the json array the changes should affect the form too.

Here is the image enter image description here

Deepak Pookkote
<div ng-repeat="(key1, value1) in myPersonObj">
    <div ng-repeat="(key, value) in value1">
        <label>{{key}}</label>
        <input type="text" name="" value="{{value}}">
    </div>
</div>

var app = angular.module("test",[]);

app.controller("MainCtrl",function($scope){

  $scope.inputs = [
    {
      "firstname" : "Test"
    },{
      "lastname" : "Test1"
    },{                           
      "Account" : [

        {"role" : "Test3"},
        {"status" : "Test4"},
      ]
    },
    {
      "Account1" : [

        {"role" : "Test3"},
        {"status" : "Test4"},
      ]
    },
    {
      "Account2" : [

        {"role" : {
          'dim3': {
            'dim4':{
              'dim5':'cccc'
            }
          }
        }

      },
        {"status" : "Test4"},
      ]
    }
  ];
$scope.person = [];
$scope.myPersonObj = [];
/*console.log($scope.keys(inputs));*/
    $scope.checkIndex1 = function(arg, myPersonObj)
    {
        if (angular.isArray(arg) || angular.isObject(arg)) {
            angular.forEach(arg, function (value, key) {
                console.log(value);
                if(angular.isObject(value) || angular.isArray(value))
                {
                    $scope.checkIndex1(value, myPersonObj);
                }
                else
                {
                    console.log("pushing");
                    myPersonObj.push(arg);
                }
            });
        }
        else
        {
            console.log("pushing1");
            myPersonObj.push(arg);
        }      
    }

    $scope.checkIndex1($scope.inputs, $scope.myPersonObj);

    console.log("myPersonObj :"+ JSON.stringify($scope.myPersonObj));

    console.log($scope.inputs);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Adding form input fields dynamically

From Dev

Dynamically adding to a listview from an object constructed via input from a dialog

From Dev

Angulajs ng-options from a json with child object

From Dev

Angulajs ng-options from a json with child object

From Dev

Dynamically adding input fields in an Angular application

From Dev

Adding input fields dynamically based on user choice

From Dev

AngulaJS input fields not loose focus when clicked

From Dev

Adding option from input dynamically

From Dev

GraphQL - Get all fields from nested JSON object

From Dev

GraphQL - Get all fields from nested JSON object

From Dev

Extract nested fields from JSON using Select-Object

From Dev

Adding fields dynamically to JSON array in angular js

From Dev

Get data directly from nested array in AngulaJS

From Dev

Get data directly from nested array in AngulaJS

From Dev

Create Input Fields using json data dynamically

From Dev

Load array from dynamically created input fields

From Dev

SAS: Dynamically determine input fields from a dataset

From Dev

Adding data to json object dynamically using angularjs

From Java

Ignore fields from Java object dynamically while sending as JSON from Spring MVC

From Dev

Take input from html field and store it in JSON object (lots of input fields)

From Dev

Dynamically generated nested tree object from array

From Dev

Adding up a value from a nested object

From Dev

How to dynamically remove fields from a json response?

From Dev

How to generate a HTML table dynamically from a nested JSON object using ngRepeat directive of AngularJS?

From Dev

Django Rest Framework: Serialize data from nested json fields to plain object

From Dev

Adding/removing input fields

From Dev

Adding input fields in HTML

From Dev

ruby: Extracting fields from nested json

From Dev

Dynamically adding properties to an Object from an existing static object in C#

Related Related

  1. 1

    Adding form input fields dynamically

  2. 2

    Dynamically adding to a listview from an object constructed via input from a dialog

  3. 3

    Angulajs ng-options from a json with child object

  4. 4

    Angulajs ng-options from a json with child object

  5. 5

    Dynamically adding input fields in an Angular application

  6. 6

    Adding input fields dynamically based on user choice

  7. 7

    AngulaJS input fields not loose focus when clicked

  8. 8

    Adding option from input dynamically

  9. 9

    GraphQL - Get all fields from nested JSON object

  10. 10

    GraphQL - Get all fields from nested JSON object

  11. 11

    Extract nested fields from JSON using Select-Object

  12. 12

    Adding fields dynamically to JSON array in angular js

  13. 13

    Get data directly from nested array in AngulaJS

  14. 14

    Get data directly from nested array in AngulaJS

  15. 15

    Create Input Fields using json data dynamically

  16. 16

    Load array from dynamically created input fields

  17. 17

    SAS: Dynamically determine input fields from a dataset

  18. 18

    Adding data to json object dynamically using angularjs

  19. 19

    Ignore fields from Java object dynamically while sending as JSON from Spring MVC

  20. 20

    Take input from html field and store it in JSON object (lots of input fields)

  21. 21

    Dynamically generated nested tree object from array

  22. 22

    Adding up a value from a nested object

  23. 23

    How to dynamically remove fields from a json response?

  24. 24

    How to generate a HTML table dynamically from a nested JSON object using ngRepeat directive of AngularJS?

  25. 25

    Django Rest Framework: Serialize data from nested json fields to plain object

  26. 26

    Adding/removing input fields

  27. 27

    Adding input fields in HTML

  28. 28

    ruby: Extracting fields from nested json

  29. 29

    Dynamically adding properties to an Object from an existing static object in C#

HotTag

Archive