0

I cant to find a way to bind the elements of the array using the data-ng-repeat directive to the html page that contains the script below. The problem is that the Quizes looks like this:

[{"quizname":"Quiz 1", "username":"musa"...}]



<script> 
   var app = angular.module("QuizApp");
   app.controller("QuizCntrl",function($scope,$http){
   var onSuccess = function(data, status, headers, config){
   $scope.Quizes = data.getQuizesResult; //Returns an size5, checked it using console.log
  };
 var promise = $http.get("http://localhost:59503/Service1.svc/GetQuizes");
 promise.success(onSuccess);
 });
</script>

So when i try doing this:

 <div data-ng-controller="QuizCntrl">
     <table>
      ...
       <tr data-ng-repeat = "quiz in Quizes">
          <td>{{quiz.username}}</td>
          <td>{{quiz.quizname}}</td>
        <tr>
       ...
      </table>

Nothing gets displayed. In the tutorials and online examples that I've done all arrays look something like this:

 $scope.array = [{username: "value".....}]

How can i work around those quotations on my field names to use the data-ng-repeat directive? Any small help will be appreciated. Thank You.

3
  • What does it output only with "quiz" in angular? The quotes doesn't matter. In both ways they are interpreted as strings, so The Problem must lie elsewhere Commented Oct 30, 2016 at 3:30
  • it displayed nothing. Anyway it now works..I'm silly I had misspelled the word repeat with reapeat. Commented Oct 30, 2016 at 3:45
  • In your example it was correct. But good it's now working! Commented Oct 30, 2016 at 3:46

1 Answer 1

1

As you see in the example, the quotes doesn't matter. Maybe you will find your mistake with the example.

And you should be doing this one:

$http.get("http://localhost:59503/Service1.svc/GetQuizes").then(onSuccess);

var app = angular.module("QuizApp", []);

app.controller("QuizCntrl", function ($scope, $http) {
  $scope.Quizes = [{"quizname":"Quiz 1", "username":"musa"}, {quizname:"Quiz 2", username:"musa 2"}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="QuizApp">
  <div data-ng-controller="QuizCntrl">
     <table>
       <tr data-ng-repeat = "quiz in Quizes">
          <td>{{quiz.username}}</td>
          <td>{{quiz.quizname}}</td>
        <tr>
      </table>
  </div>
</div>

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.