0

I am trying to display some data from an array in the view using ng-repeat but it does not work.

This is how my html looks:

<div>
        <p>loop here</p>
        <ul>
            <li ng-repeat="item in transferTest">{{item.Marks}}</li>
            <li>{{item}}</li>
            <li>{{item.Marks}}</li>
        </ul>
    </div>

And this is how my controller looks:

 $scope.resultsArray.push({"Module_Code": $scope.moduleCode, "Marks" :$scope.marks,"Recommendation" :$scope.moduleRecommendation})                                       
  $rootScope.transferTest = $scope.resultsArray;

Basically this is how my data is organized:

[
{"Module_Code": "IT", "Marks": "70", "Recommendation": "test"}
{"Module_Code": "ACC", "Marks": "30","Recommendation": "testintuber"}

It seems that I am unable to access the $rootScope.transferTest from the view.
1
  • Are you sure you don't have a transferTest defined in some other scope below rootScope? Does it need to be in rootScope at all? If it needs to be shared it would be much better to use a service for it. Commented Oct 26, 2016 at 15:20

2 Answers 2

1

Your JSON is not properly formated,

it should be,

[
{"Module_Code": "IT", "Marks": "70", "Recommendation": "test"},
{"Module_Code": "ACC", "Marks": "30","Recommendation": "testintuber"}]

DEMO

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

4 Comments

@sanjeetharan I updated the JSON, but it is still not working.
@purplewind Check the demo attached
@sanjeetharan My code is very similar to yours, but the <ul> object just refuse to display the <li> with the ng-repeat.Any idea roughly why this is happening ? I am thinking maybe the view page is initialize before the data is even written into the $rootScope.
Can I take team viewer ?
1

Your data is malformed: [ {"Module_Code"= "IT", "Marks": "70", "Recommendation": "test"} {"Module_Code**:= "ACC", "Marks:** "30","Recommendation:= "testintuber

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.