ng-repeat 用于由变量表示的数组
ng-repeat for an array represented by a variable
我正在尝试使用 ng-repeat 来显示数组。根据变量的值,数组 ng-repeat 循环应该改变。
这是我到目前为止所做的(没有用)
HTML
<body ng-app="myApp" ng-controller="myCtrl">
<h1 ng-repeat="x in selection">{{x}}</h1>
JS
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.records1 = [
"Apple",
"Orange",
"Banana",
"Mango",
];
$scope.records2 = [
"Lion",
"Tiger",
"Crocodile",
"Olephant"
];
$scope.selection = records1;
});
我做错了什么,正确的方法是什么?
我认为你应该这样做:
JS
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.records1 = [
"Apple",
"Orange",
"Banana",
"Mango",
];
$scope.records2 = [
"Lion",
"Tiger",
"Crocodile",
"Olephant"
];
$scope.selection = $scope.records1;
});
我正在尝试使用 ng-repeat 来显示数组。根据变量的值,数组 ng-repeat 循环应该改变。
这是我到目前为止所做的(没有用)
HTML
<body ng-app="myApp" ng-controller="myCtrl">
<h1 ng-repeat="x in selection">{{x}}</h1>
JS
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.records1 = [
"Apple",
"Orange",
"Banana",
"Mango",
];
$scope.records2 = [
"Lion",
"Tiger",
"Crocodile",
"Olephant"
];
$scope.selection = records1;
});
我做错了什么,正确的方法是什么?
我认为你应该这样做:
JS
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.records1 = [
"Apple",
"Orange",
"Banana",
"Mango",
];
$scope.records2 = [
"Lion",
"Tiger",
"Crocodile",
"Olephant"
];
$scope.selection = $scope.records1;
});