1

HTML (Jade):

a(href='#', data-placement='right', title="{{ someArrayOfStrings }}" tooltip)

where someArrayOfStrings is declared given a value during initialization in my angular controller:

Angular:

var myController = function($scope) {
    $scope.initialize = function(someArrayOfStrings) {
        $scope.someArrayOfStrings = someArrayOfStrings;
    }
};

var tooltip = function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs){
            $(element).hover(function(){
                $(element).tooltip('show');
            }, function(){
                $(element).tooltip('hide');
            });
        }
    };
};

Currently, this would give my tooltip content such as the following:

["string1","string2","string3"]

which is ugly as hell and totally NOT what I want.

What I want displayed is something like this:

string1
string2
string3

I have searched around and it seems like there are quite a few approaches to this but so far, I have not managed to get it to work nicely, e.g. http://jsfiddle.net/superscript18/fu7a2/6/, http://jsfiddle.net/WR76R/ and Render Html String in tooltip.

Alternatively, I could perhaps use a concatenated string delimited by <br/> tags. This would require that my tooltips accept HTML tags, however. There seems to be an tooltip option available, i.e. html: true, but I can't get it to work.

Ideas / Help?


Demo fiddle @ jsfiddle.net/zr89sq6L/6/

7
  • Used in directive .tooltip - tooltip is jquery? Commented Mar 3, 2016 at 3:58
  • It's Angular; see stackoverflow.com/questions/20666900/…, @StepanKasyanenko Commented Mar 3, 2016 at 4:59
  • Are you trying $(element).tooltip({html: 'true', container: 'body'})? Commented Mar 3, 2016 at 5:10
  • Maybe it's better to use a bootstrap intended for angular? See this angular-strap. Commented Mar 3, 2016 at 5:11
  • Can you create a jsFiddle? Commented Mar 3, 2016 at 5:13

2 Answers 2

1

Try this solution jsfiddle.

  • First, create directive that create tooltip $(element).tooltip({html: 'true'}).

  • Second, use stringArray.join('<br>') create string with br.

Example:

var myApp = angular.module('myApp', []);

myApp.controller('MyCtrl', function($scope) {
    $scope.name = 'Superhero';
    $scope.stringArray = ["string1", "string2", "string3"];

  })
  .directive('tooltip', function() {
    return {
      restrict: "A",
      link: function(scope, element) {
        $(element).tooltip({
          html: 'true'
        });
      }
    }
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<link href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="MyCtrl">
    Hello, {{name}}!
    <div ng-repeat="string in stringArray">
      {{ string }}
    </div>
    <a href="#" data-placement="right" title="{{ stringArray.join('<br>') }}" tooltip>tooltip</a>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

3 Comments

It works on the fiddle, but not on my webapp, :( My strings just look like this: string1<br>string2<br>string3. It is still not rendering the HTML.
I realized smth funny. The .run is making a weird tooltip div appear on the top left hand corner of my webapp and it says my page title (not "string1" etc.) Also, I have no idea when it appears and disappears. Looks very strange and random. It also changes the title on my browser tab, O_O. Any idea why?? My tooltips are inside body > container > some rows and columns > panel body.
Hey, that worked! Strange! Cause I thought I tried this before but it didn't work :S Maybe I made a typo back then T_T Thank you so much! :) @Stepan Kasyanenko
-1

You just need to set the title property like title="{{ stringArray.join('\u000A') }}". Please check the fiddle http://jsfiddle.net/Noblemo/u9tt9xb2/

5 Comments

It works on the fiddle, but not on my webapp, :( My strings just look like they are delimited/joined by spaces rather than new lines, e.g. string1 string2 string3.
Fyi, I am using Firefox :/ but still it doesn't show as new lines.
Which is the version of firefox?
Could you please try \n or \x0A instead of \u000A?
I tried both and both don't work, :S @NOBLE M.O. Version 44.02 on Ubuntu 14.04.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.