angularjs - ng-repeat中的ng-click中的AngularJS问题,用单引号传递字符串变量
问题描述
我在 angularjs 中遇到问题,我需要用单引号传递 {{item.Key}},item.Key 的值例如是在 ng-repeat 中设置的“蓝色”,因此 selectMoreFacets( ) 功能。第一次加载页面时,只有搜索栏可见,用户在搜索中输入关键字,按回车键,然后运行以下代码 ng-repeat。第一次加载页面时,我在控制台中收到以下错误,因为这可能是
{{'\''+item.Key+'\''}}
但是点击搜索后,页面加载正常,如果我检查元素
<a ng-click="selectMoreFacets('by_Options', optionShowMore?'more':'less', 'Color Temp')"
class="ng-binding">more...</a>
这看起来很好,当我点击<a
标签时应该可以工作。但它不起作用,当我点击
<a tag , selectMoreFacets()
函数没有被调用,也没有抛出错误。
<div ng-repeat="item in aggsOptions | limitTo:100:3" ng-hide="isLoading">
<h4><u>{{item.Key}}</u></h4>
<ul class="category-list">
<li ng-repeat="subItem in item.Aggregations.Values.Items" ng-hide="isLoading">
<span ng-class="{'label-primary label': isActive_Options(item.Key,subItem.Key)}">
<a ng-click="toggleFilters_Options(item.Key,subItem.Key)">{{subItem.Key}}</a>
</span><small class="pull-right">({{subItem.DocCount | number : fractionSize}})</small>
</li>
</ul>
<a ng-click="selectMoreFacets('by_Options', optionShowMore?'more':'less', {{'\''+item.Key+'\''}})">{{optionShowMore?"more...":"less"}}</a>
</div>
控制台窗口中的错误。
错误:[$parse:syntax] http://errors.angularjs.org/1.4.8/$parse/syntax?p0=%7B&p1=invalid%20key&p2=63&p3=selectMoreFacets(by_Options %2C%20optionShowMore%3F'more' %3A'less'%2C%20%7B%7B'%5C''%2Bitem.Key%2B'%5C''%7D%7D&p4=%7B'%5C''%2Bitem.Key%2B'%5C ''%7D%7D>
at http://localhost:53694/Scripts/angular.min.js:6:416 at s.throwError (http://localhost:53694/Scripts/angular.min.js:210:32) at s.object (http://localhost:53694/Scripts/angular.min.js:209:327) at s.primary (http://localhost:53694/Scripts/angular.min.js:206:335) at s.unary (http://localhost:53694/Scripts/angular.min.js:206:174) at s.multiplicative (http://localhost:53694/Scripts/angular.min.js:205:434) at s.additive (http://localhost:53694/Scripts/angular.min.js:205:261) at s.relational (http://localhost:53694/Scripts/angular.min.js:205:96) at s.equality (http://localhost:53694/Scripts/angular.min.js:204:425) at s.logicalAND (http://localhost:53694/Scripts/angular.min.js:204:278) <a ng- click="selectMoreFacets('by_Options', optionShowMore?'more':'less', {{'\''+item.Key+'\''}})">```
解决方案
不需要括号和引号。只要通过item.Key
:
<a ng-click="selectMoreFacets('by_Options', optionShowMore?'more':'less', item.Key)">{{optionShowMore?"more...":"less"}}</a>
推荐阅读
- java - Java Stream:没有重复的HashMap对象列表
- amazon-web-services - 即使 AWS s3 中没有文件,AWS Athena 创建外部表也会成功?
- elasticsearch - 弹性搜索 - Kafka Connect 未将正确的键值发布为文档 ID
- javascript - 反应 - '.unshift()' 的奇怪行为,但状态数组上的 '.push()' 没有
- database - 如何在带有颤动的firestore中的卡片列表中显示我的结果
- sql - 从临时表转换数据
- python - Python 语法提供
- oracle - 如何使用 Oracle 触发器克隆用户
- decompiling - 什么是分析反编译器?
- c# - Serilog 未记录到文件 ASP.Net Core 3.2