我有一个函数,该函数从打字稿函数作为对象返回颜色,文本颜色和日期值。我想将其存储在let变量中。我可以直接使用该函数,但不想复制该函数的调用。
这给了我找不到“年份”的错误
NestedScrollView
答案 0 :(得分:3)
您需要传递“ content:this”范围对象。
模板:
<ng-template let-color="getColor()" #loading>
<span class="whole-cell" [ngStyle]="{'background-color': color.color,'color': color.textColor,'font-weight':'bold','height':'25px','vertical-align': 'middle'}">
<label>{{color.Date}}</label>
</span>
</ng-template>
<ng-container *ngTemplateOutlet="loading;context:this"></ng-container>
组件:
getColor() {
return {
color: 'red',
textColor: 'blue',
Date: 'hi'
}
}
答案 1 :(得分:0)
一种可以使用的技术是滥用? *ngIf(检查支持它的角度版本)
<ng-container *ngIf="{color:getColor(year,i,dataItem.ca)}; let state">
{{state.color.Date}}
</ng-container>