0

I am looking for a context-menu directive that can tell me what was actually clicked so i can react to it.

Was playing with this but the problem of that module is that I can't figure out how to uniquely identify the element that was clicked. So I can do the correct logic on it:

I would need something that I can pass into the callback function

Controller:

$scope.items.Data = [{Code:'row1', Name:'Name1'},{Code:'row2', Name:'Name2'}]
$scope.items.Actions = [
    {
        Code: 'Action1',
        Name: 'First action'
    },
    {
        Code: 'Action2',
        Name: 'Second action'
    }   
]

var actionList = [];
for (var i = 0; i < $scope.items.Actions.length; i++) {

            actionList.push($scope.items.Actions[i].Name, function ($itemScope,$event) {
                console.log('Action executed', $scope.objectId, $itemScope,$event,$itemScope.$index);
                // Need access to $scope.items.Actions[i].Code or at least the index of the array
            });
}
$scope.contextOptions = actionList;

HTML:

<table>
    <thead>
        <tr>
            <td>Code</td>
            <td>Name</td>       
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in items.Data" context-menu="contextOptions">
            <td>{{row.Code}}</td>
            <td>{{row.Name}}</td>
        </tr>
    </tbody>
</table>
5
  • Can you show a bit more of your code including the HTML? Commented Sep 4, 2016 at 20:50
  • added more code and basically I need to identify the action that was clicked Commented Sep 4, 2016 at 21:05
  • Where is the property Data in $scope.items?? Commented Sep 4, 2016 at 21:06
  • @papakia yes as the view suggests Commented Sep 4, 2016 at 21:07
  • But your controller does not Commented Sep 4, 2016 at 21:08

1 Answer 1

1

I am using the same thing and have no issue in doing the indexing. Instead of using

for (var i = 0; i < $scope.items.Actions.length; i++) {}

Change it to

$scope.items.Actions.forEach(function(action, index){ actionList.push(action.Name, function ($itemScope,$event) { console.log('Action executed', $scope.objectId, $itemScope,$event,index); }); })

Let me know if this is what you are looking for.

Sign up to request clarification or add additional context in comments.

1 Comment

Ty was the solution to my problem

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.