0

I have to create dynamic object in angularJs.

I have a input object like below,

$scope.inputObj={
  formName:"regForm", //this will be dynamic
  fields:[]
}

i need to create a object with name "regForm" (this name will be dynamic).

Output should look like:

$scope.regForm={}; //here form name should be created as json object
2
  • 5
    $scope[$scope.inputObj.formName]={} Commented Apr 9, 2015 at 6:44
  • thank you very much. Your help is appreciable. Commented Apr 9, 2015 at 7:02

1 Answer 1

1

To create dynamic property names inside object you must use [] notation instead of dot.

As you've mentioned $scope.inputObj.formName will be containing the name of property.

So, now to create new object with that property in scope:

$scope[$scope.inputObj.formName] = {}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your valid support

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.