2016-04-28 17 views
0

財產「toLowerCase」當我試圖使用angularstrap提示它導致此錯誤每次加載的項目:angularstrap BS-提示原因的錯誤:無法讀取的不確定

<span data-title="{{item.id}}" bs-tooltip delay="500"> </span> 

它發生錯誤控制檯:

widgets.js:40761 TypeError: Cannot read property 'toLowerCase' of undefined 
at TooltipFactory (http://localhost:9000/grunt-scripts/widget.js:66317:43) 

有沒有人有這方面的經驗,請幫助我嗎?

「EDITED」:在這裏是角工具提示的代碼:

angular.module('mgcrea.ngStrap.tooltip', ['mgcrea.ngStrap.helpers.dimensions']) 

    .provider('$tooltip', function() { 

    var defaults = this.defaults = { 
     animation: 'am-fade', 
     customClass: '', 
     prefixClass: 'tooltip', 
     prefixEvent: 'tooltip', 
     container: false, 
     target: false, 
     placement: 'top', 
     template: 'tooltip/tooltip.tpl.html', 
     contentTemplate: false, 
     trigger: 'hover focus', 
     keyboard: false, 
     html: false, 
     show: false, 
     title: '', 
     type: '', 
     delay: 0, 
     autoClose: false, 
     bsEnabled: true 
    }; 

    this.$get = ["$window", "$rootScope", "$compile", "$q", "$templateCache", "$http", "$animate", "$sce", "dimensions", "$$rAF", "$timeout", function($window, $rootScope, $compile, $q, $templateCache, $http, $animate, $sce, dimensions, $$rAF, $timeout) { 

     var trim = String.prototype.trim; 
     var isTouch = 'createTouch' in $window.document; 
     var htmlReplaceRegExp = /ng-bind="/ig; 
     var $body = angular.element($window.document); 

     function TooltipFactory(element, config) { 

     var $tooltip = {}; 

     // Common vars 
     var nodeName = element[0].nodeName.toLowerCase(); 
     var options = $tooltip.$options = angular.extend({}, defaults, config); 
     $tooltip.$promise = fetchTemplate(options.template); 
     var scope = $tooltip.$scope = options.scope && options.scope.$new() || $rootScope.$new(); 
     if(options.delay && angular.isString(options.delay)) { 
      var split = options.delay.split(',').map(parseFloat); 
      options.delay = split.length > 1 ? {show: split[0], hide: split[1]} : split[0]; 
     } 

     // store $id to identify the triggering element in events 
     // give priority to options.id, otherwise, try to use 
     // element id if defined 
     $tooltip.$id = options.id || element.attr('id') || ''; 

在此行中的問題:

var nodeName = element[0].nodeName.toLowerCase(); 
+0

能否請您片斷的JavaScript代碼只是訪問提示文本測試嗎?這將幫助我們給你一個正確的答案。我懷疑有一個更正 –

+0

我剛剛在編輯問題中添加它。請看一看。 –

回答

0

Cannot read property 'toLowerCase' of undefined意味着你嘗試運行方法(String.prototype.toLowerCase())屬於未定義變量上的String對象。

function TooltipFactory(element, config) { 

    var $tooltip = {}; 

    // Common vars 
    var nodeName = element[0].nodeName.toLowerCase(); 

這是有問題的代碼,element[0].nodeName是不確定的,這意味着element[0]沒有一個叫nodeName屬性。您可以通過打印元素對象

console.debug("element[0] = %o", element[0]); 

如果element[0]<span>元素,您可以使用title財產

+0

謝謝@svarog的解釋,但我想要的是使用angurlarstrap tooltip不使用htlm的標題。我之前也爲它進行了調試,但它將錯誤日誌記錄爲變量元素='tooltip'而不是span。 –

相關問題