1

Hi I have a problem with bind data from template to controller with angularjs

The first I have object (edited)

$scope.data =  {

               }

After that I bind it to html

<input ng-model="data.item.test[0].value" />

But I controller I get

{
    item: object() {
        0: object() {value: "ok"}    
    }
}

What is need is

item = array(0: object())

How can I do it

1
  • If you want item property to be an array, define it as an array, not as object. Commented May 8, 2015 at 6:53

1 Answer 1

1

Change mode structure in controller:

$scope.data = {
    "item": []
};

and in HTML use

<input ng-model="data.item[0].value" />

Then the model object will become something like this:

{
  "item": [
    {
      "value": "ok"
    }
  ]
}

Demo: http://plnkr.co/edit/u66QJhYiduk668C54fOb?p=preview

Sign up to request clarification or add additional context in comments.

7 Comments

Can you help me again? I just updated question. problem is I have too many fields. And I can't set it manual,
Not clear what your update was and what is the question with many fields. Can you elaborate?
In the begining $scope.data = { "item" : {} }
But now it is $scope.data = { }
okay, so what is the problem? There is a demo in my answer, feel free to update it to problematic version and share so I could take a look.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.