【问题标题】:How to pass a String[] to my angular2 html template如何将字符串 [] 传递给我的 angular2 html 模板
【发布时间】:2017-02-05 11:36:55
【问题描述】:

我在组件的导出类中声明了一个数组变量;

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

我在我的 html 模板中将其显示到屏幕上,如下所示

{{barChartLabel}} 

但是当我将它放入参数值时它会失败,如下所示

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

知道我做错了什么吗?

【问题讨论】:

  • [] 直接绑定到变量,您需要删除赋值右侧的[{{}}]。此外,这本关于模板语法的入门书值得一读:angular.io/docs/ts/latest/guide/…
  • 一百万 @silentsod 你能用一点代码把它作为答案吗?
  • [chartLabelObject]="barChartLabel"

标签: javascript html css angular


【解决方案1】:

我认为您正在尝试将其传递给子组件(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

【讨论】:

    猜你喜欢
    • 2013-10-21
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多