I am having trouble understanding how to call a function on a specific instance of a directive if it meets certain criteria. In the example below, I would like to call a the function on a specific directive instance when a keyboard shortcut is pressed if it has the class focused based on ng-class. Your help is much appreciated!
http://plnkr.co/edit/P7rM3o4TADSf6rxTIRsZ?p=preview
index.html
<body ng-controller="SampleController">
<test-question
ng-repeat="n in [1,2,3]"
ng-class="{'focused': tracer.focus == n}"
focusnum = "{{n}}"
ng-click="tracer.focus = n"
>
Test Question {{n}}
</test-question>
</body>
script.js
angular.module('sampleApp', [])
.controller("SampleController", function($scope) {
$scope.tracer = {
focus: 1
}
// on keyboard shortcut call some function on a specific directive with class focused
})
.directive('testQuestion', function() {
return {
restrict: 'E',
link: function(scope, el, attrs) {
scope.someFunction = function() {};
}
}
});