Angularjs 关于ng repeat我们可以在ng repeat语句中绑定吗 对于d 为了f {{x} var-app=angular.module('myApp',[]); app.controller('customersCtrl',函数($scope){ $scope.a={ d:[1,2,3,4,5], f:[6,7,8,9] }; $scope.call=函数(val){ $scope.replace='val'; } });

Angularjs 关于ng repeat我们可以在ng repeat语句中绑定吗 对于d 为了f {{x} var-app=angular.module('myApp',[]); app.controller('customersCtrl',函数($scope){ $scope.a={ d:[1,2,3,4,5], f:[6,7,8,9] }; $scope.call=函数(val){ $scope.replace='val'; } });,angularjs,Angularjs,我正在尝试向ng repeat内容动态添加值,但它不起作用,请提供帮助 我们是否可以动态地将值添加到ng repeat本身,以便每次只需更改一个值即可更改迭代值(如上所述),如果没有更好的方法,可以在调用函数中传递值,然后将这些值分配给$scope.replace,然后更新ng repeat <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com

我正在尝试向ng repeat内容动态添加值,但它不起作用,请提供帮助
我们是否可以动态地将值添加到ng repeat本身,以便每次只需更改一个值即可更改迭代值(如上所述),如果没有更好的方法,可以在调用函数中传递值,然后将这些值分配给$scope.replace,然后更新ng repeat

<!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}}">
                    {{x}}
                </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>

对于d
为了f
  • {{x}
var-app=angular.module('myApp',[]); app.controller('customersCtrl',函数($scope){ $scope.a={ d:[1,2,3,4,5], f:[6,7,8,9] } $scope.call=函数(val){ $scope.replace=val;} } );
以下代码片段可以帮助您


对于d
为了f
  • {{x}
var-app=angular.module('myApp',[]); app.controller('customersCtrl',函数($scope){ $scope.a={ d:[1,2,3,4,5],, f:[6,7,8,9] } $scope.call=函数(val){ $scope.replace=val; } });
您希望在每次单击按钮时添加哪些值?您不是在分配传递的参数,而是在分配字符串值
“val”
非常感谢您,先生
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">       </script>
    <body>

        <div ng-app="myApp" ng-controller="customersCtrl"> 
            <button ng-click="call(a.d)">for d</button>
            <button ng-click="call(a.f)">for f</button>
            <ul>
                <li ng-repeat="x in replace">
                    {{x}}
                </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>