如何打开和关闭角UI编程popovers [英] How to Open and Close Angular-UI popovers programmatically

查看:213
本文介绍了如何打开和关闭角UI编程popovers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建popovers是从服务器获取它的内容。

I need to create popovers that gets its content from the server.

所以,我创建了以下指令:

So I created the following directive:

.directive('myPopover', [myService, function ($myService) {
        return {
            restrict: 'E',
            transclude: true,
            template: '<a href="" ng-click="wordClicked()" class="highlight" popover-trigger="manual" popover="Adequately good for the circumstances" popover-title="good enough " popover-placement="bottom" ng-transclude></a>',
            link: function (scope, element, attrs) {
                scope.wordClicked = function () {
                    if ( POPUP IS NOT SHOWING ){
                        var message = myService.getMessage({key: element.text()},
                            function () {
                                    console.info("NEED TO SHOW POPOVER WITH "+ message);
                                });
                    }
                    else {
                        console.info("NEED TO CLOSE POPOVER");
                    }
                }
            }
        }
    }]);

和成功的getMessage方法内我需要做酥料饼显现。
文档没有给出任何指示,虽然我发现做评论
通过Luthur 这里好像有一个 popover-触发=手动选项。
无法找到一个方法来编程触发它

And inside getMessage success method I need to make the popover to show. The documentation does not give any indication for that though I found comment made By Luthur here it seems like there is a popover-trigger="manual" option. Could not find a way to trigger it programmatically

更新:
我试图按照 Mosho 的意见,但我有麻烦创建自定义事件触发器酥料饼。

Update: I tried to follow Mosho advice but I am having troubles creating a popover with the custom event trigger.

请参见 plnkr

谢谢!

推荐答案

首先,如果你还没有看,这里有工具提示和popovers来源:

First, if you haven't already looked, here are the sources for tooltips and popovers:

tooltip.js

popover.js

您可以添加自定义的触发器。 Popovers使用 $提示提供商:

You can add custom triggers. Popovers use the $tooltip provider:

.directive( 'popover', [ '$tooltip', function ( $tooltip ) {
  return $tooltip( 'popover', 'popover', 'click' );
}]);

$提示的提供商 $ GET 方法,用于制造新的提示的,这里定义的:

Where the $tooltip's provider $get method, used to make new tooltip's, is defined here:

 this.$get = [ '$window', '$compile', '$timeout', '$parse', '$document', '$position', '$interpolate', function ( $window, $compile, $timeout, $parse, $document, $position, $interpolate ) {
    return function $tooltip ( type, prefix, defaultTriggerShow ) {...}

$提示提供商有以下方法:(triggerMap是在 $工具提示中定义的3触发提供开箱即用的。

The $tooltip provider has this method: (triggerMap is the 3 triggers that are defined in the $tooltip provider out of the box.

   /**
   * This allows you to extend the set of trigger mappings available. E.g.:
   *
   *   $tooltipProvider.setTriggers({'openTrigger': 'closeTrigger'});
   */
  this.setTriggers = function setTriggers ( triggers ) {
    angular.extend( triggerMap, triggers );
  };

您可以在配置块中使用它,就像这样:

You can use it in a config block, like this:

myApp.config(['$tooltipProvider', function ( $tooltipProvider ) {
  $tooltipProvider.setTriggers({'openTrigger': 'closeTrigger'}) ;
}]);

然后,您可以创建这样一个新的酥料饼的指令:

Then, you can create a new popover directive like this:

.directive('myPopover', ['$tooltip', function ( $tooltip ) {
  return $tooltip( 'myPopover', 'myPopover', 'openTrigger' );
}]);

然后触发酥料饼会像简单element.triggerHandler('openTrigger')(或 closeTrigger )其中,元素是酥料饼。

And triggering the popover would then be as simple as element.triggerHandler( 'openTrigger' ) (or closeTrigger) where element is the popover.

这篇关于如何打开和关闭角UI编程popovers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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