我使用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秒的工具提示。
答案 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()
,但这很棘手且难看,所以如果可能的话我会避免这种情况。