0
我試圖通過我的模板click
事件調用函數,但錯誤是「get不是函數」。有人可以找到問題出在哪裏嗎?如何調用typscript中的函數
我的模板:
<button class="btn btn-primary" (click)="get()">sign-up</button>
我的TS:
import {Component} from '@angular/core';
import {FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES} from '@angular/forms';
import {FormBuilder, FormGroup, Validators} from '@angular/forms'
import { Http, Headers } from '@angular/http';
import { Router, ROUTER_DIRECTIVES } from '@angular/router';
@Component({
directives: [FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES],
templateUrl : "./components/login/login.html",
})
export class Login {
//http: Http;
form: FormGroup;
constructor(public router: Router, public http: Http, fbld: FormBuilder) {
// this.http = http;
this.form = fbld.group({
email: ['', Validators.required],
phone: ['', Validators.required]
});
}
function get(){
// this.router.navigate(['/demo/signup']);
alert('hai');
}
你不需要'功能'在'get'前面的類。 –
@nlr_p:'getter'和'setter'方法在它前面不需要'function'。這會幫助你:) –