2

我正在尝试制作的 angularjs 指令存在问题。

主指令称为 tableu,它有一个 tableu-heading 和一个 tableu-body,它们都在一个表格中,如下所示:

<table>
    <tableu-heading headings='data.format'>
    </tableu-heading>
    <tableu-body data='data'>
    </tableu-body>
</table>

问题是,在 chrome 和 firefox 中(但由于某种原因不在 IE8 中)是当我调用指令时插入的结果代码的格式很奇怪。我最终得到;

<tableu>
    <tableu-heading>
    </tableu-heading>
    <tableu-body>
    <tableu-body>
    <table>
    </table>
</tableu>

这样我的嵌套指令就被放置在表中。我已经尝试了一些可能是问题的transclude思维排列,但我似乎无法解决问题。

因此,我的指令代码是:

angular.module('air.directives.tableu',[])

.directive('tableu', function () {
  return {
    restrict:'EA',
    scope: {
        data: '=',
    },
    templateUrl: 'template/tableu/tableu.html'
  };
})

.directive('tableuHeading',function() {
  return {
    restrict:'EA',
    replace: false,
    scope: {
        headings: '='
    },
    templateUrl: 'template/tableu/tableu-heading.html',
    compile: function compile(tElement, tAttrs, transclude) {


        return function link(scope, iElement, iAttrs) {

        }
    }
  };
})

.directive('tableuBody',function() {
  return {
    restrict:'EA',
    transclude: true,
    replace: false,
    templateUrl: 'template/tableu/tableu-body.html',
    compile: function compile(tElement, tAttrs, transclude) {


        return function link(scope, iElement, iAttrs) {

        }
    }
  };
})

您可以提供的任何帮助将不胜感激 - 我不能但认为解决方案可能很明显。

4

1 回答 1

2

Mark Rajcok 似乎是正确的。对我来说,解决方案是将指令作为类或属性而不是元素调用——这避免了这个特殊问题。

于 2013-06-10T10:52:57.837 回答