Search code examples
c#angularjsasp.net-mvcangularjs-ng-repeat

Why ng-repeat records multiply in combobox in Aspnet Mvc?


I am using angularjs ng-repeat for a combobox but it multiply records that n*n times.(if there is 5 record then it show 5*5=25 records)

I use ng-repeat like this:

<div class="profile-info-value userbase">
        <select class="form-control" id="DepositorID" name="DepositorID" ng-model="SearchModel.DepositorID" sc-model="SearchModel.DepositorID" sc-nullable="1">
                <option value="0">&nbsp;</option>
                <option ng-repeat="item_ in SearchModelDepositorIDs" value="{{item_.DEPO_ID}}">{{item_.DEPO_DESCRIPTION}}</option>
        </select>
</div>

and I fill SearchModelDepositorIDs like below:

$.post($scope.addressgetdepolist).done(function (Result) {
        if (Result.Success) {
                $scope['SearchModelDepositorIDs'] = Result.Data;
                $scope.$apply();
                CloseWaiting();
        }

I call this method once on formLoad.

As result returned 15 records and showed 225 records: image

When debug I see list has 15 records but anyway ng-repeat multiply records.

Can you help me for this?

Edit: Result.Data: image


Solution

  • I solved with ng-options using by an advice from my friend on Twitter.

    That's it:

    <div class="profile-info-value userbase">
            <select class="form-control searchablecombobox" ng-model="SearchModel.DepositorID" ng-options="item_.DEPO_ID as item_.DEPO_DESCRIPTION for item_ in SearchModelDepositorIDs">
                    <option value="">&nbsp;</option>
            </select>
    </div>