我是angular2中的新手。我在调用click事件时遇到问题。它给了我错误。这是我的代码:
<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"
答案 0 :(得分:1)
我猜...你可能忘了将http服务注入组件的构造函数中:
import {HTTP_PROVIDERS} from 'angular2/http';
@Component({
providers: [HTTP_PROVIDERS],
...
})
export class FormComponent {
constructor(private _http:Http) {}
postData() {
this._http.post(...);
}
}