簡體   English   中英

如何將String []傳遞給我的angular2 html模板

[英]How to pass a String[] to my angular2 html template

我在組件的導出類中聲明了一個數組變量;

 barChartLabel:string[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];

我將其顯示在我的html模板中的屏幕上,如下所示

{{barChartLabel}} 

但是當我將其放入參數值時,它失敗,如下所示

 <mychart [chartLabelObject]="[{{barChartLabel}}]"></mychart>

知道我在做什么錯嗎?

我認為您正在嘗試將其傳遞給子組件(mychart)?

在您的子component.ts中:

import { Input } from '@angular/core';

export class app {

@Input() chartLabelObject:string[];

}

父.component.html:

<app-craftinput [chartLabelObject]="barChartLabel"></app-craftinput>

https://angular.io/docs/ts/latest/cookbook/component-communication.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM