1

I've written a custom tooltip directive that requires a shared controller function to pass the data between the elements that get the tooltip and the tooltip div itself. So I've got a "tooltipCtrl" directive which I place on the container div, and then a "tooltip" directive that I put on elements that should get the tooltip on mouseover, and a "tooltipDiv" directive that I place on the element that actually gets the tooltip. Both tooltip and tooltipDiv have "require:'^tooltipCtrl'" in their definition. It's probably the wrong way to do this, but it seems to get the job done.

Unfortunately when I tried to use the directive in a custom cellTemplate for ng-grid, I get this error:

Error: [$compile:ctreq] Controller 'tooltipCtrl', required by directive 'tooltip', can't be found!

Here's the template definition:

<div tooltip="cell" class="ngCellText"><span ng-cell-text>{{row.getProperty(col.field)}}</span></div>

This doesn't happen when I use the template outside of ng-grid. Is ng-grid doing something odd when it compiles the template such that it can't find the directive on the parent element?

Here's the whole thing in a plunker: http://plnkr.co/edit/wP1cnhJGiYLP49695RKD

Thanks for any guidance!

Greg Michalec
  • 849
  • 3
  • 10
  • 17

1 Answers1

0

I think this has to do with the fact that the ngGrid directive has closed scope, line 3057:

ngGridDirectives.directive('ngGrid', ['$compile', '$filter', '$templateCache', '$sortService', '$domUtilityService', '$utilityService', '$timeout', '$parse', '$http', '$q', function ($compile, $filter, $templateCache, sortService, domUtilityService, $utils, $timeout, $parse, $http, $q) {
    var ngGridDirective = {
        scope: true,
        compile: function() {
koolunix
  • 1,995
  • 16
  • 25
  • Thanks for the response, but I don't understand - could you expand on this? What's odd is that it seems to find the 'tooltip' directive easy enough (else it wouldn't know about the linkage to tooltipCtrl), but it can't find 'tooltipCtrl'. – Greg Michalec Feb 06 '14 at 22:23
  • I don't have a direct answer to that, but just know you can't access anything from a parent controller with isolated scope. Also I would look at Mark Rajcok's answer here-> http://stackoverflow.com/questions/14539947/ angularjs-access-directives-isolated-scope-from-parent-controller – koolunix Feb 07 '14 at 03:50