gpt4 book ai didi

javascript - angularstrap bs-tooltip导致错误: Cannot read property 'toLowerCase' of undefined

转载 作者:行者123 更新时间:2023-11-28 10:49:03 25 4
gpt4 key购买 nike

当我尝试使用 Angularstrap 工具提示时,每次加载项目都会导致此错误:

<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 工具提示的代码:

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();

最佳答案

Cannot read property 'toLowerCase' of undefined意味着您尝试在 undefined variable 上运行属于 String 对象的方法 ( String.prototype.toLowerCase() )。

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 访问工具提示文本属性(property)

关于javascript - angularstrap bs-tooltip导致错误: Cannot read property 'toLowerCase' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36910479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com