我有这个表格:

    <form id="login-form" class="text-left" (ngSubmit)="submitLogin()">
      <div class="login-form-main-message"></div>
                <div class="main-login-form">
                    <div class="login-group">
                        <div class="form-group">
                            <label for="lg_username" class="sr-only">Username</label>
                            <input type="text" class="form-control" id="lg_username" name="lg_username" placeholder="username"  [(ngModel)]="username">
                        </div>
                        <div class="form-group">
                            <label for="lg_password" class="sr-only">Password</label>
                            <input type="password" class="form-control" id="lg_password" name="lg_password" placeholder="password"  [(ngModel)]="password">
                        </div>
                    </div>
                    <button type="submit" class="login-button"><i class="fa fa-chevron-right" ></i>LOGIN</button>
     </div>
</form>

在组件中,我有这个:
  submitLogin(){
          // Variable to hold a reference of addComment/updateComment

      }

我有登录组件:
import {Component, EventEmitter, Input, OnChanges} from '@angular/core';
import {Observable} from 'rxjs/Rx';
import { LoginService } from '../services/login.service';
import { Login } from '../model/login'
@Component({
    selector: 'login',
    templateUrl: 'login-form',

})
export class LoginComponent {
  // Constructor with injected service
      constructor(
          private commentService: LoginService
          ){}
      // Local properties
      private model = new Login('', '');

      submitLogin(){
          // Variable to hold a reference of addComment/updateComment
            alert('aaaa');
      }


}

现在我想要的是从 ngModel 中获取 submitLogin() 中的值,然后处理我想要的值。有什么建议吗?

最佳答案

您可以从表单中获取值:

<form #form="ngForm" id="login-form" class="text-left" (ngSubmit)="submitLogin(form.value)">

关于angular - 如何从 ngModel 中获取值(value)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42807283/

10-12 18:07