angularjs - 模板内的嵌套指令放置在顶部

标签 angularjs angularjs-directive

我尝试创建的 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>

这样我的嵌套指令就会与表内联放置。我尝试了一些可能是问题所在的嵌入思维排列,但我似乎无法解决该问题。

我的指令代码是:

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) {

        }
    }
  };
})

您能提供的任何帮助将不胜感激 - 我不得不认为解决方案可能是显而易见的。

最佳答案

马克·拉吉科克 (Mark Rajcok) 似乎是正确的。对我来说,解决方案是将指令作为类或属性而不是元素来调用 - 这避免了这个特定的问题。

关于angularjs - 模板内的嵌套指令放置在顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16518339/

相关文章:

AngularJs : event listener on http requests

AngularJS : Isolating scope in a directive with transclude set to true

angularjs - Angular JS : "active" class on menu items created by a controller

javascript - Protractor :随机测试失败

javascript - Angular : Inherited method extend in the child controller scope

javascript - 编译嵌入模板

javascript - Edge浏览器无法触发iframe onload

javascript - 创建出现在按键上的 Angular 模态指令

angularjs - angularjs 指令中的 iScroll

javascript - 使用文本 Angular 嵌入音频