【问题标题】:Errors using ng-repeat to display data in view AngularJS使用 ng-repeat 在视图 AngularJS 中显示数据时出错
【发布时间】:2016-10-26 22:47:22
【问题描述】:

我正在尝试使用 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.

【问题讨论】:

  • 您确定没有在 rootScope 下的其他范围中定义 transferTest 吗?它是否需要在 rootScope 中?如果需要共享,最好使用服务。

标签: angularjs arrays ng-repeat


【解决方案1】:

您的 JSON 格式不正确,

应该是,

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

DEMO

【讨论】:

  • @sanjeetharan 我更新了 JSON,但仍然无法正常工作。
  • @purplewind 查看附件
  • @sanjeetharan 我的代码与您的代码非常相似,但
      对象只是拒绝显示带有 ng-repeat 的
    • 。您知道为什么会这样吗?我在想也许视图页面在数据写入 $rootScope 之前就已经初始化了。
  • 我可以带团队查看器吗?
【解决方案2】:

您的数据格式不正确: [ {“Module_Code”=“IT”,“标记”:“70”,“推荐”:“测试”} {"Module_Code**:= "ACC", "Marks:** "30","Recommendation:= "testintuber

【讨论】:

    猜你喜欢
    • 2018-06-28
    • 2016-02-22
    • 2018-01-17
    • 1970-01-01
    • 2017-07-13
    • 2020-08-16
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多