I have a very simple directive that does not have an isolate scope. It's being used on a ng-repeat element and I want to limit which element out of that ng-repeat it works on. It doesn't work on every element created by the ng-repeat. So I have an attribute that evaluates an angular expression within the scope, but it appears that it's not working. I have a feeling this is because ng-repeat creates its own scope, but I think I don't have access to it. Here is the directive code:
App.directive('testDriveStep', ['$log', function($log) {
return {
link: function( $scope, element, attribs ) {
// this is the line that has trouble.
var enabled = attribs.testDriveEnabled ? $scope.$eval(attribs.testDriveEnabled) : true;
if( enabled ) {
// enable the directive otherwise do nothing
}
}
};
}]);
Here is my code I'm trying to execute:
<li ng-repeat="item in items" test-drive-step test-drive-enabled="$index == 0 && item.band == 'band1'"/>
If I remove the second part of the boolean expression in enabled attribute (ie lesson.band == 'band1'). It works in that the evaluation evaluates correctly. However, when I add the use of item it seems like item is undefined which makes me think the scope of directive isn't the same as ng-repeat. What do I need to do to fix this?