2角模板组件 [英] Angular 2 Template Component
本文介绍了2角模板组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我想创建一个自定义对话框分量,我想它插入一个声明方式的内容,应该是这样的:
Hello I want to create a custom dialog component and I want to insert it content on a declarative way, should look like this:
app.action.dialog.component.ts:
app.action.dialog.component.ts:
@Component({
selector: 'app-action-dialog',
templateUrl: 'app/template/app.action.dialog.component.html'
})
export class ActionDialog {
showing: boolean;
constructor() {
this.showing = false;
}
show() {
this.showing = true;
}
hide() {
this.showing = false;
}
}
app.action.dialog.component.html:
app.action.dialog.component.html:
<div id="overlay" class="valign-wrapper"
*ngIf="showing" (click)="hide()">
<div class="container valign">
<div class="card">
<div class="card-content">
<content select="[content]"></content>
</div>
</div>
</div>
</div>
使用例子:
<app.action.dialog>
<div content> example </div>
</app.action.dialog>
这不工作,我该怎么办呢?这可能吗?
This ain't working, how can I do this? Is it possible?
推荐答案
我正确地理解你的问题(提供一些内容到另一个组件),我认为你可以利用纳克含量
:
I correctly understand your question (provide some content to another component), I think that you could leverage ng-content
:
@Component({
selector: 'field',
template: `
<div>
<ng-content></ng-content>
</div>
`
})
export class FormFieldComponent {
(...)
}
和使用该组件像:
<field>
<input [(ngModel)]="company.address.street"/>
</field>
希望它hepls你,
蒂埃里
Hope it hepls you, Thierry
这篇关于2角模板组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文