3

I have little problem with my ng-repeat

  $http.get("/test-server/rest/servizi/listaRuoli")
    .success(function(data){
    	$scope.servizio = data;
    	console.log(data.label);
    })
 <div class ="input_form_right">
    <strong>Seleziona un Servizio</strong> (obbligatorio)<br>
    <select class="size_input_newbg">
        <option ng-repeat="x in servizio" ng-bind = "x.label"></option>
    </select>
 </div>

the problem is that I can't use track by $index because of mongodb as I read on the web. Some ideas? thank you!

2
  • 1
    Your question is a bit confusing. The title says something and the content of the question says something else. Which is it? Commented Nov 7, 2016 at 11:39
  • Have you even tried using track by $index ? Commented Nov 7, 2016 at 11:40

2 Answers 2

2

Use ng-options instead:

<select  class="size_input_newbg" ng-model="yourmodel" 
  ng-options="r.id as r.label for r in servizio"
  ng-bind = "r.label">
   <option value="" disabled="">Select One</option>
</select>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

 <style>
      .title-case {
            text-transform: capitalize;
      }
 </style>

 <div class ="input_form_right">
      <strong>Seleziona un Servizio</strong> (obbligatorio)<br>
      <select class="size_input_newbg">
           <option class="title-case" ng-repeat="x in servizio track by $index">{{x.label}}</option>
      </select>
 </div>

MongoDB has nothing to do with tracking by $index. If you are trying to remove all duplicate options, I'd recommend changing your GET call to:

$http.get("/test-server/rest/servizi/listaRuoli")
.success(function(data){
    var seenBefore = [];
    var out = [];
    for (var i=0;i<=data.length-1;i++){
         if (seenBefore.indexOf(data[i].label) == -1) {
              seenBefore.push(data[i].label);
              data[i].label = data[i].label.toLowerCase();
              out.push(data[i]);
          }
    }
    $scope.servizio = out;
    console.log(data.label);
})

Comments

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.