【问题标题】:How to call directive multiple times on node click in Angular JS?如何在Angular JS中的节点单击上多次调用指令?
【发布时间】:2014-12-24 10:13:19
【问题描述】:

我正在使用自定义指令来刷新我的页面。我已经用 D3 编写了我的 UI。它是一个由节点和链接组成的简单图。

这就是我想要做的。 当我点击图的特定节点时,它会展开到它的子图等等。

以下是控制器

*vrmUI.controller('CompleteViewController', function($scope,$location, $rootScope, $route) {
    // Assigning data 
    // onDeviceClick is called when node of graph is clicked. 


    $scope.onDeviceClick = function(item){
        $rootScope.pageContextObject = $route.current.data;
        $scope.clickedItem=item;
        $scope.completeObject =//JSON Data
        $scope.loadExpandedView=true;
        $scope.showExpandedView=true;
    };*

});

对应的html是

<div class="content-panel clearfix">

    <div id="topoheader" style="font:12px sans-serif"></div>
        // expandedView directive should get called when ever control goes inside onDeviceClick.

        <expanded-view ng-show="showExpandedView"
            ng-if="loadExpandedView" clicked-rack="clickedItem"  network-data="completeObject"
            device-click="onDeviceClick(item)"></expanded-views>    
    </div>
</div>

点击图表节点时调用设备点击。 指令是 *

vrmUI.directive('expandedView',function(){ 
    function link(scope,el,attr){
     // Processing when clicked
    }
    return{
        restrict : 'E',
        link: link,
        scope : {
            clickedItem : '=',
            onDeviceClick : '&deviceClick'
        }
    };
});

*

问题:

当我单击一次它可以完美运行,但是当我单击图形的其他节点时,我可以看到控件进入 $scope.onDeviceClick = function(item){ 但我的指令没有像第一种情况那样被调用。无论如何我可以做到这一点吗?如果您需要更多详细信息或问题不清楚,请告诉我。

谢谢

【问题讨论】:

    标签: javascript jquery angularjs node.js angularjs-directive


    【解决方案1】:

    尝试将下面的行添加到$scope.onDeviceClick 函数的开头:

    $scope.loadExpandedView=false;
    $scope.showExpandedView=false;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-02
      • 2016-06-22
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多