Input property does not work within ngx-charts template

两盒软妹~` 提交于 2019-12-12 12:11:22

问题


As per this answer I did come up with code below that works fine:

result: any;
ngOnInit() {
  this.result = getResult();
}

<ngx-charts-bar-vertical-stacked
    *ngIf="(result | async) as results"
    [results]="results"
>
</ngx-charts-bar-vertical-stacked>

Now I want to pass result as an input parameter:

@Input() result: any;

<ngx-charts-bar-vertical-stacked
    *ngIf="(result| async) as results"
    [results]="results"
>
</ngx-charts-bar-vertical-stacked>

but it is just does not work this way, the chart just does not get displayed also I can't see any errors in console. However I come up with the trick by assigning input value to another component property I declared:

data: any;
@Input() result: any;

ngOnInit() {
  this.data = this.result;
}

<ngx-charts-bar-vertical-stacked
    *ngIf="(data| async) as results"
    [results]="results"
>
</ngx-charts-bar-vertical-stacked>

So this way it works but I wonder how would you do it properly without introducing new variables and doing hacks like this.data = this.result;

来源:https://stackoverflow.com/questions/53609566/input-property-does-not-work-within-ngx-charts-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!