【问题标题】:How to trigger bootstrap popover by ng-show in angularjs如何在angularjs中通过ng-show触发引导弹出窗口
【发布时间】:2013-12-17 20:29:53
【问题描述】:

我有以下工作代码:

<input 
    value="order.value"
    name="orderValue"
    ng-pattern="/^[0-9]{0,20}$/"
    handle-save="update()">
</input>
<div 
    class="text-primary 
    icon-exclamation-sign" 
    ng-show="form.value.$error.pattern">
    Only numbers are allowed
</div>

是否可以触发引导弹出窗口而不是“只允许数字”?似乎它只会由鼠标单击或悬停触发...

【问题讨论】:

标签: angularjs twitter-bootstrap triggers popover


【解决方案1】:

对于此类交互,您可以使用 directive 并在其中使用 scope.$watch 来观察“显示”属性的变化并反映它们 - 调用“element.popover()”。

指令看起来像这样

directive('popover', function () {
  return {
    restrict: 'A',
    scope: {
      shown: '=',
    },
    link: function(scope, element) {
      scope.$watch('shown', function(shown) {
        if (shown) {
          element.popover('show');
        } else {
          element.popover('hide');
        }
      });
    }
  };
});

你可以像这样使用它&lt;div popout shown="form.value.$error.pattern"&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 2017-02-20
    • 2015-03-21
    • 2016-02-05
    • 1970-01-01
    相关资源
    最近更新 更多