显示AngularStrap下拉手动 - 如何? [英] Display AngularStrap Dropdown Manually - How?

查看:225
本文介绍了显示AngularStrap下拉手动 - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示 AngularStrap下拉手动,借力触发 $ dropdownProvider 配置这样

  //下拉列表是如何触发 - 点击|悬停|聚焦|手册
的app.config(函数($ dropdownProvider){
    angular.extend($ dropdownProvider.defaults,{
        触发器:'手动'
    });
});

点击 悬停 焦点所有工作得很好,为什么不手动?我还没有发现任何证据,这提供了API配置选项的作品。我怎样才能做到这一点?

其实,这个问题似乎是我原来的问题:放置之后已经被发现了,但现在已经关闭,并在一年后我还没有找到解决的办法依然。

问题:如何使用触发器文档=手动丢失

我掐灭了,说明我在哪里这个苦苦挣扎的例子。为了澄清我的目标,我想触发下拉我的< TextArea>在一个按键 NG-模型更改)。我希望得到的下拉列表中选择保留并调用一个函数来手动触发它,而无需使用任何默认触发选项,具体触发:手动,并以直观的方式也这样做应该根据API被提供,因此,所期望的溶液不应该被限制到任何具体的触发 - 但完全手册,以容纳许多不同的用途。

Plunker链接


 < textarea的NG-模式=前pression智能感知>< / textarea的>


  app.directive('智能感知',[功能(){
    返回{
        限制:'A',
        链接:功能(范围,ELEM,ATTRS){
          范围。$腕表(attrs.ngModel,功能(五){
                如果(ⅴ){
                  //我怎么触发下拉列表在这里按键(型号变化)?
                }
            });
        }
    }
}]);


解决方案

有关任何有兴趣,通源$ C ​​$ C挖后,我发现了指令属性 bsDropdown 名为 bsShow 通过以下实现。

  //能见度绑定支持
attr.bsShow&功放;&安培;范围。$腕表(attr.bsShow,功能(为newValue,属性oldValue){
    如果收益率(下拉|| angular.isDefined(newValue)以!);
    如果(angular.isString(newValue)以类型)newValue = !! newValue.match(?/真|(下拉)/ I);
    为newValue ===真的吗? dropdown.show():dropdown.hide();
});

这基本上是带动下拉标记,包括这一点,并绑定到 $范围值等。

 < textarea的ID =textdropNG模型=前pression智能感知BS-下拉=下拉菜单BS-秀=滴>< / textarea的>

然后我的指令中,我可以通过修改 $ scope.drop 作为约束对 BS-秀=滴

  app.directive('智能感知',[功能(){
    返回{
        限制:'A',
        链接:功能(范围,ELEM,ATTRS){
          范围。$腕表(attrs.ngModel,功能(五){
                如果(ⅴ){
                  scope.drop = TRUE; //简单 - 但作品
                }其他{
                  scope.drop = FALSE;
                }
            });
        }
    }
}]);


看来这是记录在一个项目提交作为引用<一个href=\"https://github.com/mgcrea/angular-strap/commit/8ba875e429376ccc0426c4e25a725799622e5cf9\">here.官方文档仍然只字不提这是写作的时候,考虑的这个时间表我很惊讶这个已经收到缺乏重视。

Plunker链路与 触发:手动

I am trying to display an AngularStrap dropdown manually, leveraging the trigger configuration on $dropdownProvider as such

// how dropdown is triggered - click | hover | focus | manual
app.config(function($dropdownProvider) {
    angular.extend($dropdownProvider.defaults, {
        trigger: 'manual'
    });
});

click hover focus all work fine, but why not manual? I have yet to discover any proof that this offered api configuration option works. How can I do this?

In fact, this issue seems to have been discovered after my original question positing, but is now closed and over a year later I have yet to find a solution still.

Issue: Documentation on how to use trigger=manual is missing

I have stubbed out an example that illustrates where I am struggling with this. To clarify my goal, I want to trigger the dropdown in my <textarea> on a keystroke (ng-model change). I am looking to get a hold on the dropdown and call a function to manually trigger it without using any of the default trigger options, specifically trigger: manual, and in an intuitive way to do so as should be offered according to the api, so the desired solution should not be constrained to any specific trigger - but entirely manual to accommodate many differing usages.

Plunker Link


<textarea ng-model="expression" intellisense></textarea>


app.directive('intellisense', [function () {
    return {
        restrict: 'A',
        link: function (scope, elem, attrs) {
          scope.$watch(attrs.ngModel, function (v) {
                if(v) {
                  // how do I trigger dropdown here on keystroke (model change)?
                }
            });
        }
    }
}]);

解决方案

For anyone interested, after digging through the source code, I discovered an attribute on directive bsDropdown called bsShow with the following implementation.

// Visibility binding support
attr.bsShow && scope.$watch(attr.bsShow, function(newValue, oldValue) {
    if(!dropdown || !angular.isDefined(newValue)) return;
    if(angular.isString(newValue)) newValue = !!newValue.match(/true|,?(dropdown),?/i);
    newValue === true ? dropdown.show() : dropdown.hide();
});

This essentially drives the dropdown markup to include this and bind to a $scope value as such

<textarea id="textdrop" ng-model="expression" intellisense bs-dropdown="dropdown" bs-show="drop"></textarea>

Then within my directive I can trigger visibility by modifying $scope.drop as bound on bs-show="drop"

app.directive('intellisense', [function () {
    return {
        restrict: 'A',
        link: function (scope, elem, attrs) {
          scope.$watch(attrs.ngModel, function (v) {
                if(v) {
                  scope.drop = true; // simple - but works
                } else {
                  scope.drop = false;
                }
            });
        }
    }
}]);


It appears this was documented on a project commit as referenced here. The official documentation still makes no mention of this as the time of writing, and given the timeline of this I am surprised the lack of attention this has received.

Plunker Link with trigger: manual

这篇关于显示AngularStrap下拉手动 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆