1

I have a code inside 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>

Here location.isEdit property is set on the fly.

I want to set a conditional ng-click to span. But the code above gives the following error

angular.js:11598 Error: [$parse:syntax] Syntax Error: Token ';' is unexpected, >>expecting [)] at column 29 of the expression [readOnly===false ? >>(cancel();location.isEdit = false; updateClicked = false;) : null] starting at >>[;location.isEdit = false; updateClicked = false;) : null].

I can set the variables inside the function, but I need to set the variables and call the functions on ng-click

How to use the conditional ng-click for this type of scenario?

2 Answers 2

2

You can try something like the below code,

Controller:

$scope.conditionCancelClick = function(location){
    if(!$scope.readOnly){
        $scope.cancel();
        location.isEdit = false;
        $scope.updateClicked = false;
    }
}

Template:

<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>
Sign up to request clarification or add additional context in comments.

Comments

0

try replacing ; to , as

<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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.