我正试图在Angular 2.0中使用铁列表.我已经在使用其他Polymer 1.0组件了,但是铁列表在很大程度上依赖于Light DOM.我知道我可以删除并且只是*ng-列表中的内容,但我认为这不会很好.有人有主意吗.
这里的问题是 Angular 2 解析<template>元素,尽管它们应该留给内部的 Polymer 模板化器<iron-list>。
根据我的经验,处理这种情况的最佳方法是包装<iron-list>在自定义 Polymer 元素中,并在那里定义模板。
<dom-module id="heroes-list">
<template>
<style>
:host {
display: block;
}
</style>
<iron-list items="[[items]]" selection-enabled selected-item="{{selectedItem}}">
<template>[[item]]</template>
</iron-list>
</template>
<script>
Polymer({
is: 'heroes-list',
properties: {
items: {
type: Array
},
selectedItem: {
type: Object,
notify: true
},
}
});
</script>
</dom-module>
Run Code Online (Sandbox Code Playgroud)
然后,该元素可以在任何具有双向绑定的 Angular 2 应用程序中使用,如下所示:
<heroes-list [items]="heroes" (selected-item-changed)="myHero=$event.detail.value">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
522 次 |
| 最近记录: |