2017-09-24 51 views
-1

我想用角2,使在複選框的事件作出複選框事件:如何使用angular2

<div class="panel-heading panelcolor"> 
    <span style="font-size: 15px;font-weight: bold">Date et horaire</span> 
    <div class="checkbox checkbox-inline" style="float:right"> 
     <input type="checkbox" data-md-icheck formControlName="ddd" id="inlineCheckbox12" (click)="toto($event)"> 
     <label for="inlineCheckbox12" placement="bottom"> Aller-retour </label> 
    </div> 
</div> 

組件:

toto(e){ 
alert(e); 
} 

當我點擊複選框它給了我這個錯誤:

itineraire.component.html:98 ERROR TypeError: co.toto is not a function

+0

但代碼correcte哪來的問題? –

+0

你把toto()放在哪裏? – Vega

回答

0

確保您所放置toto功能組件類內/方法,因爲這樣的:

export class itineraireComponent { 
    toto(e) { 
     alert(e); 
    } 
    ... 
} 

也,你應該使用change事件,而不是click ...

<input type="checkbox" data-md-icheck formControlName="ddd" id="inlineCheckbox12" (change)="toto($event)"> 
+0

是的,我做了,但同樣的錯誤..我不知道爲什麼會出現這個錯誤 –

+0

我剛剛測試它,它工作正常..確保你已經正確地引用了一切.. –

+0

謝謝你是對的,這是從我這個愚蠢的東西非常感謝 –