打字稿 - 组合人口

时间:2017-03-20 15:54:12

标签: angular typescript

我有一个应用程序,其中包含一个名为week-selector的组件,它只包含一个带有标题和<select>或下拉列表的div。

我想用一些团队名称填充下拉列表但是我在@Output()上有错误,错误说:

  

Generic Type&#39; EventEmitter需要1个类型的参数

我的问题:如何在团队中填充下拉列表?

这是我的week-selecotr.compnent.ts

import { Component, OnInit, Input, Output } from '@angular/core';
import{EventEmitter} from '@angular/core';

export class DropdownValue {
value:string;
label:string;

constructor(value:string,label:string) {
this.value = value;
this.label = label;
 }
}

@Component({
selector: 'dropdown',
template:
`
<form class = "ui small form segment">
<div id="WeekSubmission">
<h1> Please enter the week you are in: </h1>
<ul>
<li *ngFor="#value of values" (click)="selectItem(value.value)">    {{value.label}}</li>
</ul>
</div>
</form>
  `
})

export class WeekSelectorComponent implements OnInit {
values:DropdownValue[];

@Output()
select:EventEmitter;

constructor() {
this.values = [ new DropdownValue('Team','Liverpool')];
this.select = new EventEmitter();
}

selectItem(value){
 this.select.emit(value)
}

ngOnInit() {
 }

}

1 个答案:

答案 0 :(得分:0)

您需要声明“select”变量,如:

p = figure(x_axis_type='datetime', y_axis_type='datetime', tools='hover')

p.line(daylight_warsaw_2013.Date,daylight_warsaw_2013.Sunset, line_dash='solid', line_width=2, legend="Sunset")
p.line(daylight_warsaw_2013.Date,daylight_warsaw_2013.Sunrise, line_dash='dotted', line_width=2, legend="Sunrise")


annotations = {
    'start':{'timestamp':dt(2013, 3, 31,2,0,0),'desc':"start of daylight savings time"},
    'end':{'timestamp':dt(2013, 10, 27, 3, 0, 0),'desc':"end of daylight savings time"}
}

def auto_annotate(df,plot):
    for row in df.values(): 
        xloc = time.mktime(row['timestamp'].timetuple())*1000 
        span = Span(location=xloc, dimension='height', line_width=2, line_dash='dashed',line_color='green')
        label = Label(x=xloc, y=5000000, text=row['desc'])
        plot.add_layout(label)
        plot.add_layout(span)

auto_annotate(annotations,p)
show(p)

而不是:

@Output()select: EventEmitter<string>;

事件发射器需要该类型来表示我们正在发出的事件值的类型。在你的情况下,它是一个“字符串”。所以,我已将其声明为:

@Output()select: EventEmitter;

希望这有帮助!