0

我试图创建一个具有弹出功能的指令。我的模板不是最短的,所以我决定使用templateUrl它。然后,我决定为我的弹出框使用一个模板,所以我尝试ng-template在我的指令模板文件中使用定义,并将它与 一起使用popover-template,但我看不到工具提示。这是示例:

<script type="text/ng-template" id="myTemplate.html">
    {{label}}
</script>

<div ng-if='label.length >= 5' popover-template='myTemplate.html' popover-trigger='mouseenter'>
    {{label | limitTo: 5}}{{label.length >= limit ? '..' : ''}}
</div>
<div ng-if='label.length < 5'>
    {{label}}
</div>

为什么做不到?我这样做的主要原因是因为我想保持它干净和优雅(当然)并且我想在我的弹出框上应用一些样式。

更新:我添加了指令,虽然它可以工作并且只是为了完成图片。

angular.module('MyApp')
    .directive('myDirective', function() {
        return {
            restrict: 'E',
            scope: {
                label: '@'
            },
            templateUrl: 'my-directive.html'
        };
    });
4

0 回答 0