typescript 一个示例,显示动态地将模板注入Angular2组件的方式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript 一个示例,显示动态地将模板注入Angular2组件的方式相关的知识,希望对你有一定的参考价值。
import { NgFor } from '@angular/common'
import { Component, QueryList, TemplateRef, ViewChild, ViewChildren, ViewContainerRef } from '@angular/core'
@Component({
directives: [
NgFor
],
selector: 'component',
template: `
<ul><li #item *ngFor="let number of list">{{number}}</li></ul>
<template #template>
<li>template</li>
</template>
`
})
class _Component {
@ViewChild('template')
template: TemplateRef<any>
@ViewChildren('item', { read: ViewContainerRef })
items: QueryList<ViewContainerRef>
list: number[] = [0, 1, 2, 3, 4]
ngAfterViewInit() {
setTimeout(() => {
this.items.first.createEmbeddedView(this.template)
}, 1000)
}
}
以上是关于typescript 一个示例,显示动态地将模板注入Angular2组件的方式的主要内容,如果未能解决你的问题,请参考以下文章