来自ng-repeat如何获取每个迭代标记的范围值

时间:2017-02-15 09:10:22

标签: javascript angularjs

<!DOCTYPE html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  </head>
  <body>
    <div ng-app="myApp" ng-controller="customersCtrl">
      <button ng-click="call('d')">for d</button>
      <button ng-click="call('f')">for f</button>
      <ul>
        <li ng-repeat="x in a[replace]">{{ngController}}
          {{x}}<div><input  ng-model=well ng-click=fun()>{{well}}</div>
        </li>
      </ul>
    </div>
    <script>
      var app = angular.module('myApp', []);
      app.controller('customersCtrl', function($scope) {
        $scope.a = {
          d:[1,2,3,4,5],
          f:[6,7,8,9]
        };
        $scope.call = function(val) {
          $scope.replace=val;
        }
      });
    </script>
  </body>
</html>

这里我给出了ng-scope,它正在被迭代。现在我想访问这些特定的范围。我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:0)

试试这个

&#13;
&#13;
<!DOCTYPE html>
    <html>
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
        </head>
        <body>
            <div ng-app="myApp" ng-controller="customersCtrl"> 
                <button ng-click="call('d')">for d</button>
                <button ng-click="call('f')">for f</button>
                <ul>
                    <li ng-repeat="x in a[replace]">{{ngController}}
                        {{x}}<div><input type="text" ng-model="x" ng-click=fun()>{{x}}</div>
                    </li>
                </ul>
            </div>
            <script>
                var app = angular.module('myApp', []);
                app.controller('customersCtrl', function($scope) {
                    $scope.a = {
                        d:[1,2,3,4,5],
                        f:[6,7,8,9]
                    };
                    $scope.call = function(val) {
                        $scope.replace=val;
                    }
                });
            </script>
        </body>
    </html> 
&#13;
&#13;
&#13;

答案 1 :(得分:0)

&#13;
&#13;
<!DOCTYPE html>
    <html>
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
        </head>
        <body>
            <div ng-app="myApp" ng-controller="customersCtrl"> 
                <button ng-click="call('d')">for d</button>
                <button ng-click="call('f')">for f</button>
                <ul>
                    <li ng-repeat="x in a[replace]">{{ngController}}
                        {{x}}<div><input  ng-model=well ng-click=fun(well)>{{well}}</div>
                    </li>
                </ul>
            </div>
            <script>
                var app = angular.module('myApp', []);
                app.controller('customersCtrl', function($scope) {
                    $scope.a = {
                        d:[1,2,3,4,5],
                        f:[6,7,8,9]
                    };
                    $scope.call = function(val) {
                        $scope.replace=val;
                    }
                    $scope.fun = function(vl){alert(vl)}
                });
            </script>
        </body>
    </html> 
&#13;
&#13;
&#13;