首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角指令点击两次函数调用

角指令点击两次函数调用
EN

Stack Overflow用户
提问于 2015-08-07 11:41:52
回答 1查看 878关注 0票数 3

下面是两个指令。我的问题是,我的第二个指令中的函数addSectorAttributes在project_subtypes.html的ng单击中被触发了两次。

代码语言:javascript
复制
      .directive('projectFilter', function($compile, $timeout){
            return {
                restrict: 'E',
                templateUrl: 'project_filter.html',
                link : function(scope,element, attr){
                   //getting data and fill the html from a service 
                },
                controller: function ($scope) {
                    $scope.addSubTypes = function (event,id) {
                      var ex = $(event.currentTarget);

                      var el = $compile( "<project-subtypes typeid="+id+" class='slide-content'></project-subtypes>" )( $scope );
                        ex.parent().append(el);

                    };
                }
            }
        })

       .directive('projectSubtypes', function($compile){
                return {
                    restrict: 'E',
                    scope: true,
                    templateUrl: 'project_subtypes.html',
                    link : function(scope,element,attr){
                            //getting data and fill the html from a service
                           var id = attr.typeid; 
sectorFiltering.getSectorSubTypes(id).success(function(data) {
                        scope.sector_subtypes = data.sector_subtypes;
                    });
                        });
                    },
                    controller: function ($scope) {
                        $scope.addSectorAttributes = function (event,id) {
                            console.log("teeest"); // called twice.....
                        };
                    }                        
                }
            })

project_subtypes.html

代码语言:javascript
复制
<li ng-repeat="subtype in substype.subtypes">
        <div layout='row' class='load-attributes' ng-click=" addSectorAttributes($event, subtype.id)"></div>
 </li>

任何帮助请..。

EN

回答 1

Stack Overflow用户

发布于 2015-08-07 12:12:10

如果指令函数调用了两次,如果一次没有给出subtype.id,下一次它给了您subtype.id,那么您只需要在指令中添加条件,如下所示。

subtype.id&&addSectorAttributes($event,subtype.id)“

你好,马恩德拉

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31876900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档