typescript 将范围数据传递到 Angular2 中的 ng-content
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41510470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pass scope data into ng-content in Angular2
提问by VadimB
I'm looking for solution to pass current component scope data into ng-content
directive.
我正在寻找将当前组件范围数据传递给ng-content
指令的解决方案。
I've app-table
component template with data I want to pass into child content, using some solution like this:
我有app-table
我想传递到子内容的数据的组件模板,使用如下解决方案:
<!-- some html before -->
<table>
<!-- complex header markup with sorting/filtering support -->
<tr *ngFor="let item of data">
<ng-content [value]="item"></ng-content> //how to pass data?
</tr>
</table>
//some html after
And page template where I want to use this data:
我想在其中使用此数据的页面模板:
<app-table>
<td>{{value.Name}}</td>
...
</app-table>
Is this possible?
这可能吗?
回答by DotBert
I think you could find your answer here: Angular 2 passing html to ng-content with bindings.
我想你可以在这里找到你的答案:Angular 2passing html to ng-content with bindings。
The ng-content component is badly documented, unfortunately. It will be soon, according to the Angular GitHub issue (https://github.com/angular/angular.io/issues/3099).
不幸的是,ng-content 组件的文档很差。根据 Angular GitHub 问题(https://github.com/angular/angular.io/issues/3099),这将很快。