最近在練習 Angular @Output 與 @Input 範例時,一直卡在 @Output
我自己事先定義好一個自訂的類別 ThreeProbe ,當有 click 事件觸發時,
會把被挑選到的資料跟這事件一起用強型別(ThreeProbe)送出去。
但程式在編譯時卻一直顯示錯誤。
錯誤訊息:
Expected 0 type arguments, but got 1.
Code:
import { Component, OnInit, Output } from '@angular/core';
import { ThreeProbe } from '../three-probe';
import { EventEmitter } from 'protractor';
@Component({
selector: 'app-my-member-list',
template: `
<ol>
<li *ngFor="let member of members">
<app-my-memer (click)="select(member)" [m]='member'>
</app-my-memer>
</li>
</ol>`,
styleUrls: ['./my-member-list.component.css'],
providers:[MyMemberService]
})
export class MyMemberListComponent implements OnInit {
members:Array<ThreeProbe>;
@Output() selected=new EventEmitter<ThreeProbe>();
constructor(private myService:MyMemberService) {
this.members=myService.getMember();
}
select(selectedThreeProbe:ThreeProbe){
this.selected.emit(selectedThreeProbe);
}
ngOnInit() {
}
}
我一直是照著書打的範例啊,怎麼就是編譯不過!!
後來仔細參考了
發現自己在 import EventEmitter 時引用錯了。應該是要引用 @angular/core
也就是
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
下次在使用 QickFix 時要格外注意,別挑錯了!
沒有留言:
張貼留言