0

すべての angular テンプレートでルート html ノードを定義する必要があり、その中でディレクティブの Html を定義できます。

そのルートノードを無視する角度の方法はありますか? 例 :

私のディレクティブテンプレート:

<div class="space consuming div, and absolute positioning breaker"> 
   <div class="content positioned relative to the directives parent 1"></div>
   <div class="content positioned relative to the directives parent 2"></div>
   <div class="content positioned relative to the directives parent 3"></div>
</div>

テンプレートを

   <div class="content positioned relative to the directives parent 1"></div>
   <div class="content positioned relative to the directives parent 2"></div>
   <div class="content positioned relative to the directives parent 3"></div>

ありがとう!

4

1 に答える 1

0

テンプレートでroot使用している場合、必要な要素は 1 つだけです。replace: true

これは、カスタム要素を定義しており、次の方法で HTML で then を使用している場合に当てはまります。

<tabs>
    <pane>1</pane>
    <pane>2</pane>
</tabs>

この場合、tabs2 つのルートを持つテンプレートに置き換えると、多少の混乱が生じます。

ただし、 が必要ない場合はreplace: true、必要な要素にディレクティブを設定して、マルチルート テンプレートを割り当てることができます。そのテンプレートは、ディレクティブを持つ要素でレンダリングされます。

JS

var app = angular.module('plunker', []);

app.directive('myDirectiveOne', function() {
  return {
    template: '<p>Hello</p><p>World!</p>'
  };
})


app.directive('myDirectiveTwo', function() {
  return {
    template: '<p>Hello</p><p>World!</p>',
    replace: true
  };
})

テンプレート

    <!-- works -->
    <div my-directive-one></div>

    <!-- has problem -->
    <div my-directive-two></div>

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

于 2013-12-01T09:02:13.423 に答える