角度带工具提示默认可见

时间:2015-01-09 11:09:28

标签: angularjs angular-strap

我使用http://mgcrea.github.io/angular-strap/#/tooltips#tooltips

我不能使用范围方法($show()$hide())。请帮帮我。我怎么用这个方法?

我在ng-repeat

中输入了内容
 <div ng-repeat="item in data.queue" >

    <input type="text" maxlength="40"  bs-tooltip data-animation="am-flip-x" data-title="{{item.file.tooltip_title}}"> 

<div>

如果item.file.flag === true,我需要设置可见的工具提示,然后隐藏超过5秒的工具提示。

2 个答案:

答案 0 :(得分:1)

要获得show()和hide()方法,你必须在javascript端做所有事情。像这样:

<强>标记

<div id="div1">some</div>

<强>指令

app.directive('someThing', ['$tooltip', '$timeout', function($tooltip, $timeout){
    return {
        link: function($scope){
            $scope.someFunction = function (item){
                $timeout(function(){
                    var target = angular.element(document.getElementById('div1'));
                    var myTooltip = $tooltip(target, { title:'tip!!', trigger:'manual', placement:'top'});
                    myTooltip.$promise.then(function() { myTooltip.show(); });

                    $timeout(function(){
                        myTooltip.$promise.then(function() { myTooltip.hide(); });
                    }, 4000);
                }, 1500);
            };
        }
    };
}]);

答案 1 :(得分:0)

解决问题的Angular方法是使用data-bs-show="item.file.flag"

它会在item.file.flag == true时显示您的工具提示。

bsShow属性需要一个布尔值,因此如果你需要在5秒后隐藏,你可能会有另一个标志,并在此之后使用$timeout将其设置为false。

可以使用$show() / $hide(),但这很棘手且难看,所以如果可能的话我会避免这种情况。