Good way to dynamically open / close a popover (or tooltip) using angular, based on expression?

前端 未结 6 1258
既然无缘
既然无缘 2020-12-01 07:50

I have a form that is wired into angular, using it for validation. I am able to display error messages using ng-show directives like so:



        
6条回答
  •  北海茫月
    2020-12-01 08:24

    From Michael Stramel's answer, but with a full angularJS solution:

    // define additional triggers on Tooltip and Popover
    app.config(['$tooltipProvider', function($tooltipProvider){
        $tooltipProvider.setTriggers({
           'show': 'hide'
        });
    }])
    

    Now add this directive:

    app.directive('ntTriggerIf', ['$timeout',
    function ($timeout) {
        /*
        Intended use:
            
    */ return { restrict: 'A', link: function (scope, element, attrs) { attrs.$observe('ntTriggerIf', function (val) { try { var ob_options = JSON.parse(attrs.ntTriggerIf.split("'").join('"') || ""); } catch (e) { return } $timeout(function () { for (var st_name in ob_options) { var condition = ob_options[st_name]; if (condition) { element.trigger(st_name); } } }) }) } } }])

    Then in your markup:

    
    

提交回复
热议问题