【问题标题】:ng-grid and required directives in cell template单元格模板中的 ng-grid 和所需指令
【发布时间】:2014-02-06 20:13:12
【问题描述】:

我编写了一个自定义工具提示指令,它需要一个共享控制器函数来在获取工具提示的元素和工具提示 div 本身之间传递数据。因此,我在容器 div 上放置了一个“tooltipCtrl”指令,然后将一个“tooltip”指令放置在应该在鼠标悬停时获得工具提示的元素上,以及一个放置在元素上的“tooltipDiv”指令这实际上得到了工具提示。 tooltip 和 tooltipDiv 在其定义中都有“require:'^tooltipCtrl'”。这可能是错误的方法,但它似乎完成了工作。

不幸的是,当我尝试在 ng-grid 的自定义 cellTemplate 中使用该指令时,我收到此错误:

错误:[$compile:ctreq] 控制器 'tooltipCtrl',指令 'tooltip' 需要,找不到!

这是模板定义:

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

当我在 ng-grid 之外使用模板时,不会发生这种情况。 ng-grid 在编译模板时是否在做一些奇怪的事情,以至于在父元素上找不到指令?

这是一个 plunker 中的全部内容: http://plnkr.co/edit/wP1cnhJGiYLP49695RKD

感谢您的指导!

【问题讨论】:

    标签: angularjs angularjs-directive ng-grid


    【解决方案1】:

    我认为这与 ngGrid 指令具有封闭范围有关,第 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() {
    

    【讨论】:

    • 感谢您的回复,但我不明白 - 您能详细说明一下吗?奇怪的是,它似乎很容易找到 'tooltip' 指令(否则它不会知道与 tooltipCtrl 的链接),但它找不到 'tooltipCtrl'。
    • 我对此没有直接的答案,但只知道您无法从具有隔离范围的父控制器访问任何内容。另外我会在这里查看 Mark Rajcok 的答案-> stackoverflow.com/questions/14539947 angularjs-access-directives-isolated-scope-from-parent-controller
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 2017-07-22
    相关资源
    最近更新 更多