我需要有条件地将工具提示属性添加到元素中。我正在尝试给它添加一个ID,并在我的控制器中调用angular.element,这样我就可以在它上面使用element.attr('uib-tooltip','test')。这样做会将工具提示属性添加到元素中,但是,当我将鼠标悬停在元素上时,工具提示将不会显示。
HTML
<td id="cellTest" ng-click="ctrl.test()">
{{ parameter.current }}
</td>
Javascript
vm.test = () => {
const cellTest = angular.element(document.querySelector('#cellTest'));
cellTest.attr("uib-tooltip", "test");
}
当我单击该元素时,会在控制器中调用test()函数,并且它工作得很好。uib-tooltip=“<td>
”属性被添加到测试中。但是,工具提示不会显示。
我想补充的是,如果我将cellTest.css('color', 'red');
添加到测试()函数中,它会工作得很好。将添加样式。为什么我的工具提示不起作用?:'(
发布于 2018-07-24 13:24:27
作为变种
HTML
<td id="cellTest" uib-tooltip="test" tooltip-is-open="tooltipIsOpen" ng-click="tooltipIsOpen = !tooltipIsOpen">
{{ parameter.current }}
</td>
发布于 2018-07-24 15:33:36
你能使用“title”而不是“uib-tooltip”吗?下面是一个代码片段:
angular.module('app', [])
.controller('Controller', function() {
var vm = this;
vm.parameter = {current: 'Parameter with title'};
vm.parameter.notCurrent = 'Parameter without title';
vm.test = () => {
const cellTest = angular.element(document.querySelector('#cellTest2'));
cellTest.attr("title", "Cell 2 Test");
vm.parameter.notCurrent = 'Parameter, now with title'
}
});
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
<!doctype html>
<html ng-app="app">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
</head>
<body>
<h2>Using "title"</h2>
<div ng-controller="Controller as ctrl">
<table>
<tr>
<th>Foo</th>
<th>Bar</th>
<th>Click below</th>
</tr>
<tr>
<td>Just another cell</td>
<td id="cellTest1" uib-tooltip="test" title="Cell 1 Test">
{{ ctrl.parameter.current }}
</td>
<td id="cellTest2" ng-click="ctrl.test()">
{{ ctrl.parameter.notCurrent }}
</td>
</tr>
</table>
</div>
</body>
</html>
https://stackoverflow.com/questions/51498952
复制