Pra*_*hag 5 javascript angular
使用Angular 2版本:2.0.0-alpha.44
我试图从组件发出输出信号.我在这里关注了Angular文档 .Below是我的组件的代码
@Component({
selector: 'summary'
})
@View({
directives: [NgFor, NgIf, ROUTER_DIRECTIVES, LogoutComponent, BarChartDirective, SunburstChartDirective],
templateUrl: 'view/summary-component.html'
})
export class SummaryComponent {
@Output() loadSummary: EventEmitter = new EventEmitter();
project: Project;
data: any;
constructor(public http: Http,
public router: Router,
public xxxGlobalService: XXXGlobalService) {
console.log("SummaryComponent: Created");
this.getSummary()
}
getSummary() {
this.project = this.xxxGlobalService.getOpenedProject();
var url = "/project_summary?username="+ this.xxxGlobalService.getUser().name + "&project_id=" + this.project.id;
this.http.get(url)
.map(res => res.json())
.subscribe(
data => this.extractData(data),
err => this.logError(err),
() => console.log('SummaryComponent: Successfully got the summary')
);
}
extractData(data) {
this.data = data;
console.log("SummaryComponent: Emitting loadSummary event");
this.loadSummary.next("event");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试分配EventEmitter(下面的行)时,我收到错误说"TypeError:router_1.EventEmitter不是函数"
@Output() loadSummary: EventEmitter = new EventEmitter();
Run Code Online (Sandbox Code Playgroud)
我检查了链接并修改了线条
@Output() loadSummary: EventEmitter;
Run Code Online (Sandbox Code Playgroud)
但loadSummary似乎始终未定义.如何发出输出信号?请帮忙
从 beta.0(也许更早)开始,EventEmitter现在是angular2/core.
使用以下命令发出事件emit():
@Output() loadSummary: EventEmitter<any> = new EventEmitter();
...
this.loadSummary.emit("event");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7100 次 |
| 最近记录: |