2015-11-28 24 views
8

Tôi cố gắng triển khai chú giải công cụ với mẫu góc cạnh bên trong. Đối với điều này, tôi sử dụng "uib-tooltip-html" và tôi thêm một thuộc tính vào phần tử để biên dịch mẫu. Nhưng nó không hoạt động. Đây là mã Đây là plunker http://plnkr.co/edit/y1TvogsFFBoBVra3gO3F?p=previewchú giải công cụ trong angularjs với "uib-tooltip-html"

<html> 
<head lang="en"> 
    <meta charset="UTF-8"/> 
    <title>uib-tooltip-html test</title> 
    <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js"></script> 
    <script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular-sanitize.min.js"></script> 
    <script> 
     var app = angular.module("test", ['ngSanitize','ui.bootstrap']).config(function($sceProvider) { 
      $sceProvider.enabled(false); 
     }); 

     app.controller("testController", function($scope, $http, $interval, $sce) { 
      $scope.text = $sce.trustAsHtml('<table><tr ng-repeat="x in [1,2,3]"><td>{{ x }}</td></tr></table>'); 
     }); 
     app.directive('compileTemplate', function($compile, $parse){ 
    return { 
     link: function(scope, element, attr){ 
      var parsed = $parse(attr.uibTooltipHtml); 
      console.log(attr.uibTooltipHtml); 

      function getStringValue() { return (parsed(scope) || '').toString(); } 
      console.log(getStringValue()) 
      //Recompile if the template changes 
      scope.$watch(getStringValue, function() { 
       console.log('ca passe'); 
       $compile(element, null, -9999)(scope); //The -9999 makes it skip directives so that we do not recompile ourselves 
      }); 
     }   
    } 
}); 
    </script> 

    </head> 
<body> 

<div ng-app="test" ng-controller="testController"> 

    <p style="margin-top: 5em;" uib-tooltip="Some text" > 
     A Thing With a Tooltip 
    </p> 

    <p style="margin-top: 5em;" uib-tooltip-html="text" compile-template> 
     A Thing With an HTML Tooltip 
    </p> 

</div> 

Cảm ơn bạn trước cho câu trả lời của bạn

+0

http://stackoverflow.com/a/28189625/1061668 –

Trả lời

8

Bạn có thể sử dụng uib-tooltip-template như thế này:

<p style="margin-top: 5em;" uib-tooltip-template="'myTooltipTemplate.html'"> 
    A Thing With an HTML Tooltip 
</p> 

Và rồi trong đặt html của bạn trong myTooltipTemplate.html:

<table><tr ng-repeat="x in [1,2,3]"><td>{{ x }}</td></tr></table> 

Mẫu đi trong một tệp riêng biệt.

tài liệu: https://angular-ui.github.io/bootstrap/#/tooltip

plnkr: http://plnkr.co/edit/tiCHpd0LipixXbO4Xfa5?p=preview

+0

Làm thế nào sẽ làm việc này với nội dung động? Tôi thích điều đó rất đơn giản, nhưng tôi không thấy làm thế nào tôi có thể làm một cái gì đó như thế này: '

Actual TY
' nơi nó sẽ trở lại "Tháng: 24
YTD: 45"? – Grandizer

+0

@Grandizer, mẫu hoạt động giống như một "bao gồm" của html sẽ được hiển thị, do đó, nó sẽ hoạt động trong ngữ cảnh của div của bạn. Ví dụ:

ACTUAL TY
và bạn vẫn có thể gọi hàm trong workingdays.html:
{{ GetWorkingDays('YTD TY') }}
bubbassauro

+0

Tôi đoán đó là vấn đề của tôi, '' YTD TY "' thay đổi. Vậy biến "biểu thức" hay sự kiện $ hay biến gì đó mà tôi có thể vượt qua? – Grandizer

Các vấn đề liên quan