0

Upon initial rendering the data shows up fine, meaning if I have data for the custom fields the values are displayed on the HTML.

The problem is when I change the values of the custom fields, the changes are not attached back to the object, in other words it appears the binding is only one way for some reason.

I have the following object:

{ 
        "_id" : BinData(3, "6aUPCzvqTUuzZWlWRJCdPQ=="), 
        "name" : "MyObject", 
        "customFields" : [
            {
                "_id" : BinData(3, "ksRiQNZnuE2BKFpjbQEQaQ=="), 
                "name" : "Field 1", 
                "order" : NumberInt(1), 
                "type" : "string", 
                "isMultiValue" : false, 
                "values" : [
                    "11111"
                ]
            }, 
            {
                "_id" : BinData(3, "S9bSzoqy5EafPP0NEdbfCw=="), 
                "name" : "Field 2", 
                "order" : NumberInt(2), 
                "type" : "string", 
                "isMultiValue" : false, 
                "values" : [
                    ""
                ]
            }
        ]
    }

I have the following HTML bound to it:

                    <div ng-repeat="customField in customer.customFields">
                        <p>
                            {{customField.name}}:
                        </p>
                        <p ng-repeat="customFieldValue in customField.values">
                            <input type="text" class="form-control" ng-model="customFieldValue" />
                        </p>
                    </div>

Update: After the suggestion from @ngLover I got the binding to work correctly in this case:

Here is the new object:

{ 
    "_id" : BinData(3, "FKibZl5WDk2jprg1gY5KAQ=="), 
    "name" : "MyObject", 
    "customFields" : [
        {
            "_id" : BinData(3, "3HUUHy1FMUaxD41JcuYqQw=="), 
            "name" : "Field 1", 
            "order" : NumberInt(1), 
            "type" : "string", 
            "isMultiValue" : false, 
            "values" : [
                {
                    "value" : "Data 1"
                }
            ]
        }, 
        {
            "_id" : BinData(3, "2t0oiy5LukSSuPR9XYKwcA=="), 
            "name" : "Field 2", 
            "order" : NumberInt(2), 
            "type" : "string", 
            "isMultiValue" : false, 
            "values" : [
                {
                    "value" : "Data 2"
                }
            ]
        }
    ]
}

New HTML:

                  <div ng-repeat="customField in customer.customFields">
                        <p>
                            {{customField.name}}:
                        </p>
                        <p ng-repeat="customFieldValue in customField.values">
                            <input type="text" class="form-control" ng-model="customFieldValue.value" >
                        </p>
                    </div>
3
  • 1
    Can you please create fiddle of your code. Commented Nov 2, 2015 at 6:36
  • customField.values is an array make it a simple var like values:11111 Commented Nov 2, 2015 at 6:40
  • @ngLover I changed customField.values to be a custom object and now the binding is working fine. Commented Nov 2, 2015 at 6:58

1 Answer 1

1

remember that each ng-repeat has its own scope, so, in your second ng-repeat, ng-model="customFieldValue" is being attached to the second ng-repeat scope, not the outer scope.

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

1 Comment

child scopes inherit from parent scopes. and you can access parent scope properties using $scope.$parent.someproperty

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.