2017-02-15 67 views
0

我有一个angularJS应用程序,它利用引导UI。我试图设置一些引导工具提示,它有大量的可配置元素。我不想让自己的标记比我想要的大得多,我想将选项推到我的控制器中。AngularJS Bootstrap-UI Tooltip - 如何在控制器中配置选项

当前的标记看起来是这样的:

<p tooltip-placement="right" tooltip="{{bic.multipleIncomeTooltip()}}" tooltip-animation="true" tooltip-trigger tooltip-enable="bic.model.borrowers[bic.borrowerIndex()].income.hasMultipleEmployments"></p> 

我宁愿这个选项推到我的控制器,这样的标记可以简化为这样的事:

<p tooltip-options="bic.incomeTooltipOptions" /> 

有没有办法做到这一点?

+1

,你可以创建自己的所有值指令,并将当前标记作为模板,然后将“tooltip-options”作为默认参数,该绑定到一个控制器变量。说你的指令名为“yourTooltip”,那么你的html将是

TerryLi

回答

0

是,创建自己的指令,使用该标记,然后通过你需要

HTML

<p tooltip-options="tooltipObject"></p> 

JS

angular.module('app', []) 
.directive('tooltipOptions', function() { 
    return { 
     restrict: 'A', 
     replace: true, 
     controller: ['$scope', function($scope) { 
     }], 
     template: '<p tooltip-placement="tooltipOptions.placement" tooltip-animation="tooltipOptions.animation"></p>', 
     scope: { 
      tooltipOptions: '=' 
     } 
    } 
}); 
相关问题