我正在登錄頁面上工作。我想要做的是在類validateLogin()
和submit()
中有兩個功能。當點擊登錄按鈕我已成功提交,我可以得到用戶名和密碼。如何在angular2中的同一控制器內的另一個函數中調用一個函數
我想在我的提交函數中調用我的validateLogin函數,但我不能稱之爲我的崇高文本在validateLogin上顯示錯誤,並且在我的chrome瀏覽器中沒有收到任何錯誤。
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {FormBuilder,Validators} from "@angular/common";
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
public loginForm: any;
public commentOnTimeOut: any;
constructor(private navCtrl: NavController, public form:FormBuilder) {
this.loginForm = this.form.group({
"email":["",Validators.required],
"password":["",Validators.required]
})
}
validateLogin(cb){
window.setTimeout(() => {
if (this.loginForm.value.email == 'admin' && this.loginForm.value.password == 'admin123') {
console.log("invoking If part");
cb('valid User');
}
else {
console.log("invoking elsePart");
cb('Invalid User');
}
}, 3000);
}
submit(){
console.log(this.loginForm.value);
console.log(this.loginForm.value.email);
console.log(this.loginForm.value.password);
validateLogin(this.loginForm.value.email, this.loginForm.value.password, (response) => {
console.log(response);
this.commentOnTimeOut = response;
})
this.commentOnTimeOut = "Validating User";
console.log(this.commentOnTimeOut);
}
}
如何在我的提交函數中調用我的函數validateLogin?
下面是一個demo plunker它做工不錯
錯誤:
GET http://localhost:8100/build/js/app.bundle.js in my console.
In my serve i get error like
TypeScript error: /home/panini/AutoSparParts/app/pages/home/home.ts(40,5): Error TS2663: Cannot find name 'validateLogin'. Did you mean the instance member 'this.validateLogin'?
上面的錯誤我正在調用任何幫助
是的,我嘗試'this.'和我得到像'TypeScript錯誤:/ home/panini /AutoSparParts/app/pages/home/home.ts(40,5):錯誤TS2346:提供的參數不匹配調用目標的任何簽名。 ' –