使用ng-repeat在视图中显示数据的错误AngularJS

时间:2016-10-26 13:18:49

标签: angularjs arrays ng-repeat

我正在尝试使用ng-repeat从视图中的数组中显示一些数据,但它不起作用。

这就是我的html外观:

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

这就是我的控制器的外观:

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

基本上这就是我的数据组织方式:

[
{"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.

2 个答案:

答案 0 :(得分:1)

您的JSON格式不正确,

它应该是,

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

<强> DEMO

答案 1 :(得分:1)

您的数据格式错误: [ {“Module_Code”=“IT”,“标记”:“70”,“推荐”:“测试”} {“Module_Code **: =”ACC“,”标记:**“30”,“建议:=”testintuber