Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用AngularJS在HTML中进行连接_Angularjs - Fatal编程技术网

使用AngularJS在HTML中进行连接

使用AngularJS在HTML中进行连接,angularjs,Angularjs,我的AngularJS控制器(称为“搜索”)具有以下变量: this.redInfo = [...]; this.blueInfo = [...]; this.greenInfo = [...]; this.tableSelector = ''; //this can either be 'red', 'blue', or 'green' 我正在尝试执行一个ng repeat,其中重复的信息取决于表选择器。这可能吗?这就是我现在拥有的: <div ng-repeat="row in {{

我的AngularJS控制器(称为“搜索”)具有以下变量:

this.redInfo = [...];
this.blueInfo = [...];
this.greenInfo = [...];
this.tableSelector = ''; //this can either be 'red', 'blue', or 'green'
我正在尝试执行一个
ng repeat
,其中重复的信息取决于
表选择器。这可能吗?这就是我现在拥有的:

<div ng-repeat="row in {{'search.' + search.tableSelector + 'Info'}} track by $index">

您当前的尝试是不可能的。您可以创建一个返回适当重复数组的方法:

this.getColorArray = function() {
   if (this.search.tableSelector == "red") return this.redInfo
   ...
}
然后再重复一遍:

<div ng-repeat="row in search.getColorArray() track by $index">


这可能会影响性能,具体取决于阵列站点和页面上的其他观察者。如果您知道
tableSelector
更改的位置,则始终可以在该位置设置重复数组,避免$digest循环中的额外开销。

您当前尝试的是不可能的。您可以创建一个返回适当重复数组的方法:

this.getColorArray = function() {
   if (this.search.tableSelector == "red") return this.redInfo
   ...
}
然后再重复一遍:

<div ng-repeat="row in search.getColorArray() track by $index">

这可能会影响性能,具体取决于阵列站点和页面上的其他观察者。如果您知道
表选择器更改的位置,则始终可以在该点设置重复数组,避免$digest循环中的额外开销。

使用属性访问器:

<div ng-repeat="row in search[search.tableSelector + 'Info'] track by $index">

使用属性访问器:

<div ng-repeat="row in search[search.tableSelector + 'Info'] track by $index">