1

I'm using a MEAN application, and now I want to read data from my database, allow users to edit it, and update the changes to the database. Everything is working fine, except for the nested repeat, which value's I'm able to get, but not save to the database.

Code:

<div class="controls" ng-repeat="(key, module) in project.website.data.modules">
                    <input type="checkbox" name="modules" value="{{key}}" data-ng-model="module.active" id="{{key}}"><label for="{{key}}"> module: {{key}} = {{module.active}}</label><br>

                    <div class="features_settings" ng-repeat="(key2, feature) in module.data">
                        <input type="text" name="data" value="{{key2}}" data-ng-model="feature" id="{{key2}}"><label for="{{key2}}"> feature {{key2}}, value= {{feature}}</label><br>
                    </div>
                </div>

Gives as result for uniekewebsitefeature.data.title: (which is correct because I set the default value as "asdf")

feature title, value= asdf

Mongoose schema:

website: {
    active: { type: Boolean },
    data: { 
        domain: { type: String },
        modules: {
            aboutus: {
                active:{ 
                    type: Boolean,
                    default: false
                },
                data: {
                    title: { 
                        type: String,
                        default: ""
                    },titlerererere: { 
                        type: String,
                        default: ""
                    },
                    text: { 
                        type: String,
                        default: ""
                    }
                }
            },
            contact: {
                active: { 
                    type: Boolean,
                    default: false
                },
                data: {
                    fields: [
                        {
                            type: String,
                            values: [String],
                            label: String,
                            placeholder: String
                        }
                    ],
                    recipient: { 
                        type: String,
                        default: ""
                    }
                }
            },
            uniekewesitefeature: {
                active: { 
                    type: Boolean,
                    default: false
                },
                data: {
                    title: { 
                        type: String,
                        default: "asdf"
                    },
                    text: { 
                        type: String,
                        default: ""
                    }
                }
            }
        }
    }
}

client controller

// Update existing Project
    $scope.update = function() {            
        var project = $scope.project;

        project.$update(function() {
            $location.path('projects/' + project._id);
        }, function(errorResponse) {
            $scope.error = errorResponse.data.message;
        });
    };

server controller

exports.update = function(req, res) {
var project = req.project;

project = _.extend(project , req.body);

project.save(function(err) {
    if (err) {
        return res.status(400).send({
            message: errorHandler.getErrorMessage(err)
        });
    } else {
        res.jsonp(project);
    }
});

};

When I set a MODULE to active/false, it works fine and saves the changes to the database, but when I save a FEATURE of that module (which is nested) it doesn't save to the database, even tough it is able to get the value from the database.

Any ideas?

user3004798
  • 191
  • 1
  • 1
  • 11

1 Answers1

0

Finally fixed it, needed these changes:

<div class="controls" ng-repeat="(key, module) in project.website.data.modules">
                    <label for="{{key}}"> module: {{key}} = {{module.active}}</label>
                    <input type="checkbox" name="modules" value="{{key}}" data-ng-model="module.active" id="{{key}}"><br>

                    <div class="features_settings" ng-repeat="(key2, feature) in module.data track by $index">
                        <label for="{{key2}}">Feature: {{key2}} , value = {{module.data[key2]}}</label>
                        <input type="text" class="form-control" name="features" data-ng-model="module.data[key2]" id="{{key2}}"><br>
                    </div>
                </div>

Hopefully it helps someone else in the feature :)

user3004798
  • 191
  • 1
  • 1
  • 11