我正在尝试使用angular-ui的工具提示功能向我的用户显示特定字段无效但似乎工具提示只能在某些预定义的触发器上显示.除了那些触发器之外,我有什么办法可以触发工具提示吗?
例如:
<input
type="text"
tooltip="Invalid name!"
tooltip-position="right"
tooltip-trigger="myForm.username.$invalid">
Run Code Online (Sandbox Code Playgroud) 我试图手动关闭一个引导程序弹出窗口,以便当我点击document或body不是弹出窗口上的任何地方时关闭它.
我发现最接近完成此任务的是创建一个指令(找到这个答案),但这是一个手动触发器,如果变量是true或false.
如果我点击任何不是popover的东西,任何人都可以帮我弄清楚如何让它关闭吗?
我不介意使用jQuery $(document).click(function(e){});我不知道如何调用close.
<div id="new_button" popover-template="plusButtonURL" popover-placement="right" popover-append-to-body="true" popover-animation="false">+</div>
Run Code Online (Sandbox Code Playgroud)
通常popover-trigger="focus"会这样做,但我的popover包含需要点击的内容.ng-click如果我使用焦点触发器,我的内部弹出窗口会被忽略,因此我正在寻找一种不那么传统的方法来解决这个问题.
我需要创建从服务器获取其内容的弹出窗口.
所以我创建了以下指令:
.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");
}
}
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
在getMessage里面的成功方法我需要让popover显示出来.该文件没有给出任何指示的,虽然我的发现促使通过Luthur评论这里好像有一个 …
javascript popover angularjs angular-ui angular-ui-bootstrap
我正在尝试以编程方式切换工具提示(如此处提到的:https://stackoverflow.com/a/23377441)并使其完全正常运行,除了一个问题.为了使它工作,我必须具有硬编码的工具提示触发器和工具提示属性,如下所示:
<input type="text" tooltip-trigger="show" tooltip="" field1>
Run Code Online (Sandbox Code Playgroud)
在我的工作指令中,我能够更改工具提示属性并触发工具提示,但是如果我尝试将这两个属性保留并尝试动态设置它们,则ui-bootstrap不会提取它们并且不会显示工具提示.
HTML
<input type="text" field2>
Run Code Online (Sandbox Code Playgroud)
JS
myApp.directive('field2', function($timeout) {
return {
scope: true,
restrict: 'A',
link: function(scope, element, attrs) {
scope.$watch('errors', function() {
var id = "field2";
if (scope.errors[id]) {
$timeout(function(){
// these attrs dont take effect...
attrs.$set('tooltip-trigger', 'show');
attrs.$set('tooltip-placement', 'top');
attrs.$set('tooltip', scope.errors[id]);
element.triggerHandler('show');
});
element.bind("click", function(e){
element.triggerHandler('hide');
});
}
});
},
};
});
Run Code Online (Sandbox Code Playgroud)
我不想在html中对这些属性进行硬编码,那么我该如何动态设置这些属性并获取ui-bootstrap来获取它们呢?
这是一个具有工作(field1)和非工作(field2)指令的plunker:http://plnkr.co/edit/mP0JD8KHt4ZR3n0vF46e