简体   繁体   English

在Angular 2中的自定义模板中声明变量

[英]Declare variable in custom template in Angular 2

How can I declare variable that isn't coming from parent component? 如何声明不是来自父组件的变量? In this example rowData comes from p-column but I need to declare another variable. 在此示例中,rowData来自p列,但我需要声明另一个变量。

<p-column *ngFor="let h of header">
    <template let-ms="rowData" pTemplate="body" let-m="getMetricByName(ms.metrics, h)">
                {{m.name}} //for example
    </template>
</p-column>

There is currently no way to declare variables in the template. 当前无法在模板中声明变量。

See also angular's ng-init alternative in Angular 2 另请参阅Angular 2中的angular的ng-init替代方案

This issue seems related https://github.com/angular/angular/issues/15020 这个问题似乎与https://github.com/angular/angular/issues/15020相关

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM