为什么在使用ajax调用时争用多次显示角度?

时间:2014-08-05 23:32:15

标签: javascript jquery angularjs twitter-bootstrap angularjs-directive

我的演示中有两个问题。我正在制作一个弹出窗口。我应该打开图标点击(这里是星形图标)。当我点击星形图标时,我能够看到我想要的弹出屏幕但问题是当我点击另一个图标/星形图标时,它打开另一个弹出窗口,而不关闭第一个弹出窗口。我需要在时间显示弹出一个..

  • 1)我们可以一次显示一个弹出。只显示一个弹出 一次。

    2)当我包含在我的plunker(tooltip.js和pop over插件)时。它显示鼠标悬停事件的竞争。但当我删除它时,它显示在点击事件为什么?

这是plunker with scripts tooltip和popover .display on click?

http://plnkr.co/edit/OYiawflIBnpJ1PKx02LG?p=preview

这是插件显示器上的这些插件显示在事件上为什么? http://plnkr.co/edit/OYiawflIBnpJ1PKx02LG?p=preview

 <script src="https://dl.dropboxusercontent.com/s/a98aey2mlu0h511/bootstrap-tooltip.js"></script>
 <script src=" https://dl.dropboxusercontent.com/s/s1imyubboz1qjtl/bootstrap-popover.js?m="></script>

enter image description here

1 个答案:

答案 0 :(得分:0)

如果你还在解决这个问题,那么以下是解决方案。虽然我不确定这是否是最佳方式,因为我从AngularJS开始。

var getTemplate = function(contentType, scope, element) {

    var template = $templateCache.get("templateId.html");

    $.ajax({
        type: "GET",
        url: 'pop.html',
        dataType: 'html',
        success: function(data) {
          var options = {
            content: data,
            placement: "right",
            html: true,
            date: scope.date,
        };
    $(element).popover(options);

    //FIND ALL POPOVERS AND HIDE THEM EXCEPT CURRENT ONE//
    $(element).on("show.bs.popover",function(t,e){
      $("span[mypopover]").not(this).popover('hide');
    });

  },
  error: function(data) {
    alert(data);
  }
    });

    return template;
};

以下是行:

$(element).on("show.bs.popover",function(t,e){
    $("span[mypopover]").not(this).popover('hide');
});

Plunker:http://plnkr.co/edit/WM0K8sdPVHSNeuIlLBim

相关问题