AngularJS:ng-repeat工作不正常

时间:2017-08-08 17:57:21

标签: php angularjs

我想要一个代码列表

这是我的代码:

 <div ng-repeat="s in CPS" class="dropdown-content">

  <a class='activation' 
    href='javascript:void(0)' 
    data-value='update_status_active.php?sr_id={{s.id}}' 
    data-toggle='modal' 
    data-target='#activation'>

    {{s.name}}

   </a>

</div>

“CP”中有10条记录 但我根据“CPs”中最后一条记录的值得到一个链接

问题是什么?

JSON数组:

 $scope.CPs=
 [
      { "id" : 1, "name" : "user1"},
      { "id" : 2, "name" : "user1"},
      { "id" : 3, "name" : "user1"},
      { "id" : 4, "name" : "user1"},
      { "id" : 5, "name" : "user1"},
      { "id" : 6, "name" : "user1"},
      { "id" : 7, "name" : "user1"},
      { "id" : 8, "name" : "user1"},
      { "id" : 9, "name" : "user1"},
      { "id" : 10,"name" : "user1"}
  ];

2 个答案:

答案 0 :(得分:1)

您的代码中有拼写错误。您的ng-repeat

应该是CP s 而不是CP S
 <div ng-repeat="s in CPs" class="dropdown-content">

  <a class='activation' 
    href='javascript:void(0)' 
    data-value='update_status_active.php?sr_id={{s.id}}' 
    data-toggle='modal' 
    data-target='#activation'>

    {{s.name}}

   </a>

</div>

答案 1 :(得分:0)

这是一个有效的例子

angular.module('myApp',[]).controller('myCtrl',function($scope){
  $scope.CPs=
   [
        { "id" : 1, "name" : "user1"},
        { "id" : 2, "name" : "user1"},
        { "id" : 3, "name" : "user1"},
        { "id" : 4, "name" : "user1"},
        { "id" : 5, "name" : "user1"},
        { "id" : 6, "name" : "user1"},
        { "id" : 7, "name" : "user1"},
        { "id" : 8, "name" : "user1"},
        { "id" : 9, "name" : "user1"},
        { "id" : 10,"name" : "user1"}
    ];
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="s in CPs" class="dropdown-content">

  <a class='activation' 
    href='javascript:void(0)' 
    data-value='update_status_active.php?sr_id={{s.id}}' 
    data-toggle='modal' 
    data-target='#activation'>

    {{s.name}}

   </a>

</div>
</div>