1

Here I have two mongo collections. Contents from the first collection is listed using ng-repeat. While looping this three ng-repeats are provided since I am fetching key value pair. The first ng-repeat for looping the collection then the two for loopong the key value pairs of an object array inside each document. So in my second collection I want to insert this object array along with a new key value pair to each index. This is my first mongo collection, i have an object array like this

    "highlight" : [ 
    {
        "status" : "upcoming"
    }, 
    {
        "status" : "overdue"
    }, 
    {
        "status" : "today"
    }
]

and i have looped this in ng-repeat my html is like this

    <div layout="row" ng-repeat="list in dynamicSettingsCtrl.features.settings">
    <fieldset class="standard">
        <md-checkbox aria-label="Checkbox 1" ng-model="moreOptions">
            <p>{{list.name}}</p>
        </md-checkbox>

        <div layout-gt-sm="row">
            <div ng-if="moreOptions">
                <form name="dashboard">
                    <md-input-container class="md-block" flex-gt-sm>
                        <label>Set Limt</label>
                        <input ng-model="dynamicSettingsCtrl.setValues.maxLimit" ng-pattern="/^(\d)+$/" />
                        <p class="alert" ng-show="dashboard.maxLimit.$error.pattern">Numbers only, please.</p>
                    </md-input-container>
                    <div ng-repeat="highlight in list.highlight">
                        <span ng-repeat="(key, value) in highlight">Set the limit where <b>{{key}}</b> is <b>{{value}}</b></span>
                        <md-input-container class="md-block" flex-gt-sm>
                            <label></label>
                            <input ng-model="dynamicSettingsCtrl.setValues.upLimit[$index]
                            " ng-pattern="/^(\d)+$/" />
                        </md-input-container>
                    </div>
                    <md-button class="md-raised md-primary" ng-click="dynamicSettingsCtrl.addCount()">Submit</md-button>
                </form>
            </div>
        </div>
    </fieldset>
</div>

after entering values the expected new mongo collection should look like this.

Now i want to store limit for each of this status like

  "highlight" : [ 
    {
        "status" : "upcoming",
        "limit":"10"
    }, 
    {
        "status" : "overdue",
        "limit":"1"`
    }, 
    {
        "status" : "today",
        "limit":"3"
    }
]

I want to set limit for each status. that is I want to set limit of status=overdue to 1 and so on. since the ng-model has same name for all the key value pair when i try adding limit every field changes to same. So i tried using index,then it was OK! but i know that using index is not a proper method. Somebody suggest me how to work with ng-init on this, or any other possible method. How can i get the correct values to my controller. How to insert the values to my second collection? Thanks in advance

Aysha Azura
  • 179
  • 1
  • 2
  • 15
  • post some fiddle link so that we can have hands on experience on your problem. – Stark Buttowski Apr 27 '16 at 11:53
  • did not understand your question exactly. If you want to use ng-repeat try this Set the limit {{item.status}} is {{item.limit}} – Nishi Apr 27 '16 at 12:56
  • possible duplicate of http://stackoverflow.com/questions/19544904/ng-repeat-access-key-and-value-for-each-object-in-array-of-objects – Stark Buttowski Apr 27 '16 at 13:09
  • No this question is not a duplicate http://stackoverflow.com/questions/19544904/ng-repeat-access-key-and-value-for-each-object-in-array-of-objects, i want to know how to define ng-model for ng-repeat of key value pair... while he asked how to get the exact key value pair instead og getting index as key. – Aysha Azura Apr 27 '16 at 13:12

0 Answers0