Angular 如何检索输入值并打印到控制台?
我想在console.log中打印与输入用户名和输入密码有关的值。见我的表格:Angular 如何检索输入值并打印到控制台?,angular,ionic2,Angular,Ionic2,我想在console.log中打印与输入用户名和输入密码有关的值。见我的表格: <form> <ion-list> <ion-item> <ion-label fixed>Username</ion-label> <ion-input type="text"></ion-input> </ion-item>
<form>
<ion-list>
<ion-item>
<ion-label fixed>Username</ion-label>
<ion-input type="text"></ion-input>
</ion-item>
<ion-item>
<ion-label fixed>Password</ion-label>
<ion-input type="password"></ion-input>
</ion-item>
<button ion-button color="secondary" clear full style="font-style: bold; text-align: center;">Forgot Password?</button>
<button ion-button color="secondary" type="submit" full>Login</button>
</ion-list>
</form>
如何在单击“登录”按钮后在控制台中检索输入和打印值?使用form builder,了解更多有关Angular中的被动表单的信息 ngSubmit与submit事件之间的区别: 但是,ngSubmit确保表单在 处理程序代码抛出,这是提交和 导致实际的http post请求。让我们使用ngSubmit来代替 最佳做法是:
使用form builder,了解更多有关Angular中的被动表单的信息 ngSubmit与submit事件之间的区别: 但是,ngSubmit确保表单在 处理程序代码抛出,这是提交和 导致实际的http post请求。让我们使用ngSubmit来代替 最佳做法是:
我建议大家关注这个关于表单对你有帮助的博客。你正在使用angular 2,对吗?@suraj angular Core:2.2.1ok..angularjs标签代表1.x,使用angular 2代表2.xquestions@suraj非常感谢。我建议大家关注这个关于表单对你有帮助的博客。你正在使用angular 2,对吗?@suraj angular Core:2.2.1ok..angularjs标签代表1.x,使用angular 2代表2.xquestions@suraj非常感谢。我本周开始工作,几乎什么都不知道。非常感谢。伟大的成功了。我是PT-BR,不客气。试着在这个官方网站上阅读更多关于Angular文档的内容,我这周刚开始,几乎什么都不知道。非常感谢。伟大的成功了。我是PT-BR,不客气。尝试在这个官方网站上阅读更多关于Angular文档的信息
<form [formGroup]="formVar" (ngSubmit)="onSubmit()">
<ion-list>
<ion-item>
<ion-label fixed>Username</ion-label>
<ion-input type="text" formControlName="username"></ion-input>
</ion-item>
<ion-item>
<ion-label fixed>Password</ion-label>
<ion-input type="password" formControlName="password"></ion-input>
</ion-item>
<button ion-button color="secondary" clear full style="font-style: bold; text-align: center;">Forgot Password?</button>
<button ion-button color="secondary" type="submit" full>Login</button>
</ion-list>
</form>
export class FormComponent implements OnInit {
formVar: FormGroup;
constructor(private fb: FormBuilder) {}
ngOnInit() {
this.formVar = this.fb.group({
username: '',
password: ''
});
}
onSubmit() {
console.log(this.formVar.value);
}
}