基本上,我在组件 1 的模板中有这样的东西。
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
这在组件 2 的模板中,它是组件 1 的兄弟
<div class="test">
<h1>component 2</h1>
</div>
我想要的是当组件 2 中的特定变量,比如说,"toggled" = true
组件 2 的模板应该是这样的
<div class="test">
<h1>component 2</h1>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
我正在使用角度版本 4.0.0 。我阅读了有关 templateoutlet 的信息,但无法弄清楚如何在不同的组件之间共享它。有没有办法从一个组件复制模板片段并在另一个组件中使用它?