Add line break within tooltips

后端 未结 27 2516
北恋
北恋 2020-11-28 02:23

How can line breaks be added within a HTML tooltip?

I tried using
and \\n within the tooltip as follows:



        
27条回答
  •  执念已碎
    2020-11-28 02:39

    AngularJS with Bootstrap UI Tolltip (uib-tooltip), has three versions of tool-tip:
    

    uib-tooltip, uib-tooltip-template and uib-tooltip-html

    - uib-tooltip takes only text and will escape any HTML provided
    - uib-tooltip-html takes an expression that evaluates to an HTML string
    - uib-tooltip-template takes a text that specifies the location of the template
    

    In my case, I opted for uib-tooltip-html and there are three parts to it:

    1. configuration
    2. controller
    3. HTML

    Example:

    (function(angular) {
    
    //Step 1: configure $sceProvider - this allows the configuration of $sce service.
    
    angular.module('myApp', ['uib.bootstrap'])
           .config(function($sceProvider) {
               $sceProvider.enabled(false);
           });
    
    //Step 2: Set the tooltip content in the controller
    
    angular.module('myApp')
           .controller('myController', myController);
    
    myController.$inject = ['$sce'];
    
    function myController($sce) {
        var vm = this;
        vm.tooltipContent = $sce.trustAsHtml('I am the first line 

    ' + 'I am the second line-break'); return vm; } })(window.angular); //Step 3: Use the tooltip in HTML (UI)
    other Contents

    For more information, please check here

提交回复
热议问题