2016-04-07 35 views
-3

Angular2 'de yeni. Click olayı çağrılırken sorun yaşıyorum. İşte click olayı angular2 içinde çalışmıyor

<form> 
    <input ngControl="email" type="email" placeholder="Your email"> 
    <input ngControl="password" type="password" placeholder="Your password"> 
    <button (click)="postData()">Log in</button> 
</form> 

Benim bileşenidir: İşte benim kodudur

import {Component} from 'angular2/core'; 
import {NgForm} from 'angular2/common'; 
import { Router } from 'angular2/router'; 
@Component({ 
    selector: 'my-form', 
    templateUrl: 'app/form.component.html' 
}) 
export class FormComponent { 
    postData(){} 
}; 

Bana hata veriyor:

EXCEPTION: Error during evaluation of "click" 
+1

Neden göstermediniz postData() 'nin içeriği? Sorun nerede –

+0

Cevabımda eklediğim plunker ile yeniden üretmeye çalışabilir misin? –

cevap

1

Ben muhtemelen enjekte unuttum ... sanırım edeceğiz Bileşeninizin yapıcısına http hizmeti:

import {HTTP_PROVIDERS} from 'angular2/http'; 
@Component({ 
    providers: [HTTP_PROVIDERS], 
    ... 
}) 
export class FormComponent { 
    constructor(private _http:Http) {} 
    postData() { 
     this._http.post(...); 
    } 
} 
+0

Harika bir tahmin :). –

+0

HTTP_PROVIDER, HttpModule ile değiştirildi. – user2584621