我想在Angular项目的typescript类中引用关键字"this".但它无法使用.我总是得到我想要改变的变量没有定义的错误.这是我的实现:
export class ContactComponent implements OnInit {
contactForm: FormGroup;
errorMsg:string = '';
redirect = "";
loggedIn(): void {
this.redirect = "dashboard";
console.log("success");
Run Code Online (Sandbox Code Playgroud)
在我的HTML中,重定向变量连接到routerLink,如下所示:
<a [routerLink]="redirect"></a>
Run Code Online (Sandbox Code Playgroud)
我已尝试使用其他函数中的其他变量,但始终存在相同的错误.
编辑:
loggedIn函数在另一个函数中作为"success"参数调用,如下所示:
submitForm(): void {
DBEventProxy.instance().dbevent.login(this.contactForm['username'],
this.contactForm['password'], this.loggedIn, this.failed);
}
Run Code Online (Sandbox Code Playgroud)
登录功能需要参数用户名,密码,成功功能,失败功能.