gpt4 book ai didi

angular - 如何从 ngModel 中获取值(value)?

转载 作者:太空狗 更新时间:2023-10-29 17:50:12 24 4
gpt4 key购买 nike

我有这个表格:

    <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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com