angularjs - 如何让多行工具提示与 AngularJS 一起工作?
问题描述
span
我有一个简单的任务:在 AngularJS 中获取多行工具提示。按照我在网上阅读的各种说明,我尝试过:
- 使用 ng-attr-title 然后作为回车。
- 使用 data-html 和 data-original-title 然后
作为回车。 - 使用 data-html 和 data-title 然后
作为回车。
这些似乎都不起作用。我还能尝试使用 AngularJS 获得多行工具提示吗?
罗伯特
解决方案
您需要使用 $sce.trustAsHtml 将 html 绑定到多行的 ng-attr-title。见下文,
var app = angular.module('tooltipApp',[]);
var ctrl = app.controller('tooltipAppCtrl',['$scope','$sce',function($scope, $sce){
$scope.text = $sce.trustAsHtml('Line1 \n Line2');
}])
<body ng-app='tooltipApp'>
<div ng-controller='tooltipAppCtrl'>
<span ng-attr-title={{text}}>See tool tip</span>
</div>
</body>
推荐阅读
- python - 在我的 Windows 7 上安装 pip 很困难
- javascript - 将状态数组发送到另一个组件以在 REACT.js 中呈现
- c - 在arduino中将两个uint8字节转换为uint16字节的最佳方法是什么?
- angular - 如何通过Angular中的属性启用常量导入模板中的组件而无需代理?
- ajax - 操作方法返回原始 json 数据而不是 ASP.NET Core 2.2 中的视图
- python-3.x - 如何在 Python 中将字节字符串转换为字节?
- firebase-realtime-database - Exoplayer在recyclerview中播放22-25次后停止工作并显示空白屏幕
- javascript - 反应运行时我的反应智能感知不起作用
- html - 无法让两个特定的小部件出现在同一个 html 文档中(从 .Rmd 文件编写),但任何一个都可以单独工作
- c++ - 导入模块的标准方式