Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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
Css angularjs中的类型错误_Css_Angularjs - Fatal编程技术网

Css angularjs中的类型错误

Css angularjs中的类型错误,css,angularjs,Css,Angularjs,我试图根据某些条件将列表中的某些值标记为字体红色和rest默认值。当我试图为列表中的特定数据分配布尔值时,我遇到了“TypeError:无法分配到123的只读属性'match'; 我的代码是: angular.forEach($scope.searchResults,函数(值,索引){ //填充搜索结果 $scope.searchResults[index].name=“ABC”; $scope.searchResults[index].linkedRecords=[]; if(//检查某些条

我试图根据某些条件将列表中的某些值标记为字体红色和rest默认值。当我试图为列表中的特定数据分配布尔值时,我遇到了“TypeError:无法分配到123的只读属性'match'; 我的代码是:

angular.forEach($scope.searchResults,函数(值,索引){
//填充搜索结果
$scope.searchResults[index].name=“ABC”;
$scope.searchResults[index].linkedRecords=[];
if(//检查某些条件){
$scope.searchResults[index].linkedRecords[i]=“123”;
$scope.searchResults[index].linkedRecords[i].match=true;
}
});

{{source}}
{{source}}


您将属性的值设置为
123
,然后尝试访问名为
'match'
的属性

$scope.searchResults[index].linkedRecords[i] = 123;
此时,
$scope.searchResults[index].linkedRecords[i]
的值为
123

这意味着这条线:

$scope.searchResults[index].linkedRecords[i].match=true;
相当于:

(123).match = true;
这将不起作用,因为数字类型是不可变的,这意味着您不能在其直接对象表示上添加或修改属性


您可能希望在对象内包装或装箱您的号码。然后您可以向该对象添加其他属性

$scope.searchResults[index].linkedRecords[i] = { value: 123, match: true };
然后,您的HTML将看起来像这样

<span data-ng-repeat="source in searchResult.linkedRecords" >
  <span ng-if="!source.match">{{ source.value }}</span>
  <span ng-if="source.match" style="color: red">{{ source.value }}</span>
  <br>
</span>

{{source.value}}
{{source.value}}


知道如何在html中实现这一点吗?我需要设置一些内容,并使列表中的项目显示为红色。您能提供更多的代码吗?可能是$scope.searchResults的示例数据集?将数字包装在对象中。
$scope.searchResults[index].linkedRecords[i]={value:123,match:true}
然后在HTML中进行
source.match
source.value
。@Dan Prince:非常感谢…:)