如何将值从文本框传递到打字稿文件

How to pass values from textbox to typescript file

请帮助我如何将我的文本框值传递给 typescript

<div>
      <input type="text" [(ngModel)]="Email" />
        <input type="text" [(ngModel)]="Password" />

        <input type="button" class="btn btn-success" value="Submit" (click)="Validation()" />

    </div>

Student.ts
这是我的 class 它有我在 studentController

中使用的这个调用的电子邮件和密码
  export class Validationclass {
            Email: string;
            Password: string;
        }
export class studentController {
        public val: Validationclass;

        Validation() {
            if (this.val.Email != null && this.val.Password != null) {
                alert('ok')
            }
            else
                alert("Emptr");

        }

您需要像这样将 ngModel 分配给控制器中的正确变量:

<div>
      <input type="text" [(ngModel)]="val.Email" />
      <input type="text" [(ngModel)]="val.Password" />

      <input type="button" class="btn btn-success" value="Submit" (click)="Validation()" />

</div>

确保在您的控制器中像这样初始化 ValidationClass:

ngOnInit() {
  val = new Validationclass(); 
}