【发布时间】:2016-04-01 09:48:40
【问题描述】:
RE DUPLICATE:“这个问题之前已经问过并且已经有了答案。”
所以这个问题是在我提出这个问题的 10 天后提出的??有人不知道如何读取时间戳。
我在 Angular 2 中苦苦挣扎,这使得在 Angular 1 中做一些微不足道的事情变得困难甚至不可能,尤其是在没有大量多余代码和/或 DOM 节点的情况下。 :(
在 Angular 1 中,我有一个查询控件,它对输入框中的击键进行复杂的处理,并在下拉列表中动态显示结果。被搜索的项目可以是任何类型,下拉列表项目可以是简单的字符串或复杂的内联模板。
例如,我可能会使用它查询用户对象列表并使用默认模板(例如toString)显示它们:
<search-box [query-provider]='userFinder'> </search-box>
我在其他地方也有类似的搜索,但我希望结果列表包含每个用户的更丰富的视图,因此我提供了一个内联模板,作为搜索框的子项:
<search-box [query-provider]='userFinder'>
<!-- this is used as a template for each result item in the
dropdown list, with `result` bound to the result item. -->
<div>
<span class='userName'>result.name</span>
<span class='userAge'>result.age</span>
<address [model]='result.address'><address>
</div>
</search-box>
我的搜索框实现需要确定是否有任何子内容可用作模板,并在搜索框模板中的正确位置使用它。
@Component({
select: 'search-box',
template: `
<div somestuff here>
<input morestuff here>
<ul this is where my dropdown items will go>
<li *ng-for="#item of model.listItems"
TEMPLATE FOR ITEMS SHOULD GO HERE
</li>
</ul>
</div>`
...
使用 Angular 1,我可以轻松地将子模板嵌入到该位置并将其绑定到适当的范围,或者我可以动态编译模板。我根本无法让它在 Angular 2 中工作。
如果我在那里使用<ng-content>,它只会出现在第一个<li>。
【问题讨论】:
-
你有同样的东西吗?
标签: angular angular2-template angular2-directives