2

I have the following code.

<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

<div ng-controller="PopoverDemoCtrl">
     Hello, All
    <img class="tip" data-placement="bottom" src="http://static.loanstreet.com.my/assets/common/glasses.png" popover="{{my_html}}" popover-trigger="mouseenter">
</div>
  </body>
</html>

and js file

angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('PopoverDemoCtrl', function ($scope) {
  $scope.my_html = '1. No Lock-In period &lt;br&gt;2. No withdrawals allowed (Non-Flexi) &lt;br&gt;3. For extra repayment to principal, minimum amount must be RM1000 and above &lt;br&gt;4. Only Non-ZEC option is available5. For completed or BUC property';
});

I want to display the popover template at the bottom and also the '<br&gt' show as they are when displayed. I want the string to display as HTML. Attavhed is my plunkr file.

http://plnkr.co/edit/1Ei09Mny89EbCUnLWgUX

Kingsley Simon
  • 2,090
  • 5
  • 38
  • 84
  • possible duplicate of [How do I create an AngularJS UI bootstrap popover with HTML content?](http://stackoverflow.com/questions/16722424/how-do-i-create-an-angularjs-ui-bootstrap-popover-with-html-content) – Phil Mar 03 '15 at 05:14

1 Answers1

0

You need to override the default html template of popover and use $sce service for binding html with it.

Use $sce for unsafe data:-

angular.module('ui.bootstrap.demo').filter('unsafe', ['$sce', function ($sce) {
    return function (val) {
        return $sce.trustAsHtml(val);
    };
}]);

Override template of default popover:-

angular.module("template/popover/popover.html", []).run(["$templateCache", function ($templateCache) {
    $templateCache.put("template/popover/popover.html",
      "<div class=\"popover {{placement}}\" ng-class=\"{ in: isOpen(), fade: animation() }\">\n" +
      "  <div class=\"arrow\"></div>\n" +
      "\n" +
      "  <div class=\"popover-inner\">\n" +
      "      <h3 class=\"popover-title\" ng-bind-html=\"title | unsafe\" ng-show=\"title\"></h3>\n" +
      "      <div class=\"popover-content\"ng-bind-html=\"content | unsafe\"></div>\n" +
      "  </div>\n" +
      "</div>\n" +
      "");
}]);

Plunker

Credits

Community
  • 1
  • 1
squiroid
  • 13,809
  • 6
  • 47
  • 67