[Angular 2] Generate and Render Angular 2 Template Elements in a Component
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了[Angular 2] Generate and Render Angular 2 Template Elements in a Component,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1484字,纯文字阅读大概需要3分钟。
内容图文
![[Angular 2] Generate and Render Angular 2 Template Elements in a Component](/upload/InfoBanner/zyjiaocheng/1128/2766fa23150d49ddb76715794f3614df.jpg)
Angular 2 Components have templates, but you can also create templates inside of your templates using Angular 2 ViewContainer’s createEmbeddedView
for more visual control of how you want to generate elements inside of your Angular 2 templates.
import {Component, ViewChild, ViewContainerRef, ComponentFactoryResolver, ViewChild} from‘@angular/core‘; import {SimpleService} from"../../serivces/simple.service"; import {WidgetThree} from"../widgets/widget-three.component"; @Component({ moduleId: module.id, selector: ‘home‘, templateUrl: ‘home.component.html‘ }) export class HomeComponent { @ViewChild(‘container‘, { read: ViewContainerRef }) container; @ViewChild(‘template‘) template; constructor(private resolver: ComponentFactoryResolver, private simpleService: SimpleService) { } ngAfterContentInit(){ const WidgetFactory = this.resolver.resolveComponentFactory(WidgetThree); this.container.createComponent(WidgetFactory); this.container.createComponent(WidgetFactory); this.container.createComponent(WidgetFactory); this.container.createComponent(WidgetFactory); this.container.createComponent(WidgetFactory); } onClick(){ this.container.createEmbeddedView( this.template ) } }
<template #template> <h3>tempalte title</h3> <section>tempalte section</section> <footer>template footer</footer> </template>
原文:http://www.cnblogs.com/Answer1215/p/5901581.html
内容总结
以上是互联网集市为您收集整理的[Angular 2] Generate and Render Angular 2 Template Elements in a Component全部内容,希望文章能够帮你解决[Angular 2] Generate and Render Angular 2 Template Elements in a Component所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。