javascript - 有条件地点击 AngularJS
问题描述
我里面有代码ng-repeat
<tr ng-repeat="location in assetLocations track">
<span class="fa fa-remove fa-lg text-danger" style="cursor: pointer;"
ng-show="location.isEdit"
ng-click="readOnly===false ? (cancel();location.isEdit = false; updateClicked = false;) : null"></span>
</tr>
这里location.isEdit
属性是动态设置的。
我想将条件 ng-click 设置为span
. 但是上面的代码给出了以下错误
angular.js:11598 错误:[$parse:syntax] 语法错误:令牌';' 出乎意料,>>expecting [)] 在表达式 [readOnly===false 的第 29 列?>>(cancel();location.isEdit = false; updateClicked = false;) : null] 从 >>[;location.isEdit = false; updateClicked = false;) : null]。
我可以在函数内部设置变量,但我需要设置变量并调用函数ng-click
如何在这种情况下使用条件 ng-click?
解决方案
你可以试试下面的代码,
控制器:
$scope.conditionCancelClick = function(location){
if(!$scope.readOnly){
$scope.cancel();
location.isEdit = false;
$scope.updateClicked = false;
}
}
模板:
<tr ng-repeat="location in assetLocations track">
<span class="fa fa-remove fa-lg text-danger" style="cursor: pointer;"
ng-show="location.isEdit" ng-click="conditionCancelClick(location)"></span>
</tr>
推荐阅读
- algorithm - 如何打印最长回文子序列?如果有多个 LPS,我们需要打印从最低索引开始的一个
- appium - Appium启动活动重置应用程序
- javascript - 单击处理程序一键触发两次
- python - 在 Pandas 中获取列的最大总和值
- django - 使用 Django 检查 firebase DB 中是否存在值
- next.js - PostGraphile:makeExtendSchemaPlugin 中的 pgSettings user.id
- sql - Teradata/SQL - 根据重复的列值返回整行
- json - 如何在 VB.Net 中使用模式验证 JSON 文件?
- python - 从父类实例创建子类实例,并从子类实例调用父方法
- eclipse - 无法从 Eclipse 登录到 Azure