AngularJs应用程序不显示uib工具提示

时间:2017-06-29 08:18:25

标签: angularjs

我正在尝试在角度js中实现当在li省略号中显示工具提示时,我的代码位于

之下

依赖注入:

angular.module('spt', ['ui.router', 'ngStorage', 'ngAnimate', 'ui.bootstrap', 'ui.slimscroll', 'angular-google-analytics', 'jmdobry.angular-cache',
    'stpa.morris', 'angularReverseGeocode', 'chart.js', 'ui.calendar', 'ui.date',
    'me-lazyload', 'angularUtils.directives.dirPagination', 'angular-loading-bar', 'base64',
    'nemLogging', 'ui-leaflet', 'angular-google-adsense', 'dropstore-ng', 'ngVideo', 'angular-google-adsense', 'cgBusy', 'duScroll', 'angularGrid', 'infinite-scroll'
]);

在HTML中:

<p class="contactEmail">
<ul style="max-width: 200px;">
<li uib-tooltip="{{email}}" tooltip-enable="flag" show-tooltip-on-text-overflow="flag" style="overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;">
<i class="ion-email"></i> 
Email : {{email}}
</li>
</ul>
</p>

JS:

angular.module('spt').directive('showTooltipOnTextOverflow',
    function ($timeout) {
      return {
        restrict: 'A',
        link: function(scope, element, attrs) {
      var el = element[0];
      scope.$watch(function(){
        return el.scrollWidth;
      }, function() {
        var el = element[0];
        if (el.offsetWidth < el.scrollWidth) {
          //console.log('ellipsis is active for element', element);
          attrs.tooltipEnable = "true";
        } else {
          //console.log('ellipsis is NOT active for element', element);
        }
      });
    }
      };
    });

控制器:

function ContactController(
    $scope,
    $rootScope,
    $modal,
    $log,
    $sce,
    ContactService,
    Utility,
    SettingsService,
    Session,
    APPLICATION,
    RESPONSE,
    CONSTANTS) {
    $log.debug('in ContactController');
    //function Declaration
    $scope.closeModelInstance = closeModelInstance;
    $scope.showDropdown = showDropdown;
    $scope.selectItem = selectItem;
    $scope.showBlock = false;
    $scope.showBlockMessage = false;
    $scope.blockMessage = '';
    $scope.syncContacts = syncContacts;

    $scope.flag = true;
    $scope.email = "sdajkdsjsadklsdajkasldjsdakljsadklsdadsa@adsjsdsadkjadsjk.it";
    if (Utility.redirectToDashboard(Session.getValue(APPLICATION.currentDeviceId)) === true) {
      return true;
    }
    $rootScope.isChildSelected1 =  Session.getValue('isChild');
    var params = {};
    params.id = Session.getValue(APPLICATION.currentDeviceId);
    $log.debug('contacts');
    $scope.items = {};
    $scope.blockType = {
      message: false,
      Contacts: false
    };

1 个答案:

答案 0 :(得分:1)

您无法使用静态属性来执行此操作! 使用范围内的变量,例如

$scope.myVar = false;

<强> HTML

<p class="contactEmail">
    <ul>
        <li uib-tooltip="{{item.email}}" 
            tooltip-enable="myVar" 
            show-tooltip-on-text-overflow="myVar">
            <i class="ion-email"></i> Email : {{item.email}}
        </li>
    </ul>
</p>

<强> JS

angular.module('spt').directive('showTooltipOnTextOverflow', function () {
    return {
        restrict: 'A',
        scope: {
           showTooltipOnTextOverflow: "="  
        },
        link: function(scope, element, attrs) {
            var el = element[0];
            scope.$watch(function(){
                 return el.scrollWidth;
            }, function() {
                 var el = element[0];
                 if (el.offsetWidth < el.scrollWidth) {
                    scope.showTooltipOnTextOverflow = true;
                 }
                 else {
                     scope.showTooltipOnTextOverflow = false;
                 }
            });
        }
     };
});

工作小提琴==&gt; http://plnkr.co/edit/EGHPncgOVvubU9iBlJdx?p=preview