如何在Angular Foundation Popover内容中添加换行符?

时间:2015-06-23 19:53:41

标签: angularjs zurb-foundation haml

这看起来应该是一个简单的问题,但我最初想到的事情变得更加复杂。

我的Angular Foundation Popover指令中有几个项目,我想用换行符分隔。

.div{ 'popover' => "Name: {{ user.name }} /br Age: {{ user.age }}", 'popover-trigger' => 'click' }

在这行html中添加换行符的解决方案是什么?

1 个答案:

答案 0 :(得分:0)

这非常棘手。如果您正在使用angular-foundation(并且我真的建议使用它),您可以将官方popover模板修改为HTML不安全 - 而不是在popovers中使用HTML:

JS

"use strict";

// app definition - don't forget to include angular-foundation module
angular.module("app", ["mm.foundation"]);

// just o controller, nothing special
angular
  .module("app")
  .controller("MainController", MainController);

  function MainController() {
    var vm = this;

    vm.name = "John Doe"
    vm.email = "john.doe@example.com"
  }

// unsafe filter - this is used in the template below
angular
  .module("app")
  .filter("unsafe", unsafe)

  function unsafe($sce) {
    return function (val) {
      return $sce.trustAsHtml(val);
    };
  };

// oficial popover template modification
angular
  .module("template/popover/popover.html", [])
  .run(["$templateCache", function($templateCache) {
    $templateCache.put("template/popover/popover.html",
      "<div class=\"joyride-tip-guide\" ng-class=\"{ in: isOpen(), fade: animation() }\">\n" +
      "  <span class=\"joyride-nub\" ng-class=\"{\n" +
      "    bottom: placement === 'top',\n" +
      "    left: placement === 'right',\n" +
      "    right: placement === 'left',\n" +
      "    top: placement === 'bottom'\n" +
      "  }\"></span>\n" +
      "  <div class=\"joyride-content-wrapper\">\n" +
      "    <h4 ng-bind-html=\"title | unsafe\" ng-show=\"title\"></h4>\n" +
      "    <p ng-bind-html=\"content | unsafe\"></p>\n" +
      "  </div>\n" +
      "</div>\n" +
      "");
}]);

HTML

<main ng-app="app" ng-controller="MainController as vm">
  <div class="row">
    <div class="small-12 column">
      <div popover="{{vm.name + '<br />' + vm.email}}" popover-trigger="mouseenter">
        <h1>Hover me!</h1>
      </div>
    </div>
  </div>
</main>

您正在使用CodePen example

你也可以制定自己的指令来同时拥有HTML安全弹出窗口和HTML不安全弹出窗口 - 或者你可以使用tooltip insetead,它默认支持HTML不安全(指令tooltip-html-unsafe)。