【问题标题】:Tooltip of AngularUI not shown for divs within ng-repeatng-repeat 中的 div 未显示 AngularUI 的工具提示
【发布时间】:2016-10-31 20:03:12
【问题描述】:

我正在尝试使用 AngularUI 在网站的某些 div 上显示工具提示。目标是在用户进入网站时已经显示它们。这就是为什么tooltop-is-open 设置为true。但是,这不适用于重复组中的元素(即通过 ng-repeat 创建的 div)。我错过了什么?

这是 HTML:

<script >
angular.module('testApp', ['ui.bootstrap']);

angular.module('testApp')
.controller('testController', ['$scope', function($scope) {

    $scope.demo = [1, 2, 3, 4, 5, 6];

}]);
</script>
<!DOCTYPE html>
<html lang="en" ng-app="testApp">
    <head>
        <meta charset="utf-8">
        <title>Hello World</title>

        <script src="bower_components/angular/angular.min.js"></script>
        <script src="bower_components/angular-animate/angular-animate.min.js"></script>
        <script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script>
        <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
        <link rel="stylesheet" href="bower_components/bootstrap-css-only/css/bootstrap.min.css"/>
        <script src="index.js"></script>

    </head>
    <body ng-controller="testController" >

        <!-- works -->
        <div >
            <h1 uib-tooltip="hallo" 
             tooltip-is-open="true" 
             tooltip-placement="bottom">Title</h1>
        </div>

        <!-- does not work -->        
        <div ng-repeat="a in demo">
            <h2 uib-tooltip="hallo"
                 tooltip-is-open="true" 
                 tooltip-placement="bottom">{{ a }}</h2>
        </div>

    </body>
</html>

【问题讨论】:

  • 它似乎对我有用,这是plunkr
  • @PankajParkar 不,它不起作用,因为工具提示应该立即显示,而不是在悬停后显示
  • @devqon 谢谢提醒先生,我完全误读了问题
  • 这似乎是uib-tooltip 的问题,因为当您超时时,它确实有效:plunker
  • 可能与摘要循环序列有关

标签: javascript html angularjs angular-ui-bootstrap angular-ui


【解决方案1】:

在 ngRepeat 中使用 uib-tooltip-html 代替:

<div ng-repeat="a in demo">
    <h2 uib-tooltip-html="'hallo'" tooltip-is-open="true" tooltip-placement="bottom">
        {{ a }}
    </h2>
</div>

看起来像一个错误

【讨论】:

  • 不要忘记工具提示内容周围的内引号
  • 有趣。在上面@PankajParkar 提供的 plunkr 中,它可以工作。但在本地却没有。我仔细检查了我是否设置了引号。
  • 我接受这个答案,因为它似乎是最好的解决方案。不过,看起来至少存在一个错误。
  • angular-ui/bootstrap on GitHub打开了一个问题
猜你喜欢
  • 1970-01-01
  • 2019-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-12
  • 2019-12-15
  • 1970-01-01
相关资源
最近更新 更多