2016-04-07 16 views
-3

click2.Iを呼び出すときに問題があります。エラーが発生します。ここに私のコードは次のとおりです。ここでclickイベントがangular2で動作しません

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

は私のコンポーネントです:

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(){} 
}; 

それは私にエラーを与える:

EXCEPTION: Error during evaluation of "click" 
+1

'postData()'の内容ですか?それはどこに問題がありますか –

+0

あなたは私の答えに追加したプランナーを再現しようとすることができますか? –

答えて

1

私は...あなたはおそらく注入するのを忘れて推測しますhttpサービスをコンポーネントのコンストラクタに追加します。

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

素晴らしい推測:)。 –

+0

HTTP_PROVIDERがHttpModuleに置き換えられました – user2584621

関連する問題