角度组件:没有模板替换选项? [英] Angular Component: no template replace option?
问题描述
在新的 AngularJS 1.5 组件概念中,似乎没有替换选项(如这是指令)。
It looks like there is no "replace" option in new AngularJS 1.5 Component concept (like it was for directives).
如果我想要表格行 < TR> <,你会建议什么? / code>元素作为组件?在有效的HTML方面是不可能的?
What would you suggest if I want to have table row <TR>
element as component? Is it not possible in terms of valid HTML?
真实的例子:mailBox组件里面有邮件组件。通过标记mail-box-component是表格,邮箱是tr。
Real example: mailBox component has mail components inside. By markup mail-box-component is table, and mail-box is tr.
<mail-box>
<mail ng-repeat="mail in $ctrl.mails" mail="mail"></mail>
<mail-box>
UPD :相关关于指令的讨论 - 为什么在AngularJS中不推荐使用替换?
UPD: related discussion about directives - Why is replace deprecated in AngularJS?
推荐答案
由于不推荐使用replace:true标志,因此不再使用-angular-way
This is not possible the-angular-way anymore since the replace: true flag has been deprecated
替换:true标志出现了比解决方案更多的问题,这就是它被删除的原因。
因此你不能再以这种方式构建指令并提供有效的table-tr-td标记。
the replace: true flag had come up with more problems than solutions which is why it was removed. therefore you can not build directives in such a way anymore and provide valid table-tr-td markup.
然而,有两个原因导致这不是看起来很糟糕:
However, there are two reasons why this is not as bad as it looks:
-
如果没有table,tr,td等,你可以做任何你想做的事。
只使用div,span等元素和一些css
you can do everything you want to do without table, tr, td, etc. just using elements like div, span, etc. and some css on it
web-components(指令是第一次尝试模拟
)它们并不意味着代表标记的这些小片段。
他们被认为是一个功能齐全的组件实际上是
做某事。所以无论你想用你的tr做什么,你都认为值得围绕它构建一个元素指令,它可能不是b $ b。
web-components (and directives were a first attempt to simulate them) are not meant to represent such small fragments of the markup. they are more thought of as a fully functional component actually doing something. so whatever you want to do with your tr that you think it's worth building an element-directive around it, it probably isnt.
也许,你可以做的是使用属性指令代替:
Maybe, what you can do is using an attribute-directive instead:
<tr my-mail-directive></tr>
你的my-mail-directive在tr元素上做了魔术
and your my-mail-directive does the magic on the tr element
这篇关于角度组件:没有模板替换选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!