Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这个 plunk取自 Angular 开发人员指南,但对我来说没有意义。它只是应该显示 transclude 的基本功能,我理解,但是在渲染的输出中你会看到突然有一个span标签。那个是从哪里来的?它不是模板的一部分。
span
由于您的嵌入只是一个文本(实际上是一个隐含的span),因此需要在编译 HTML 时添加它。
为避免这种情况,您可以手动将文本包裹在任何标签周围,例如 a <div>,以便按原样插入。
<div>
如果你真的不想在两者之间有任何标签,你可以compile在你的指令中编写你自己的方法,并将文本设置为element直接,使用elem.text(content)而不是elem.html(content)
compile
element
elem.text(content)
elem.html(content)