[英]Populate input, when value in input changes (Angular)
I have two inputs, one for Landlord Name, and second for Organization Name 我有两个输入,一个用于房东名称,第二个用于组织名称
Here is code 这是代码
<div class="form-group">
<label>{{l("Name")}}</label>
<input #nameInput class="form-control" type="text" name="name" [(ngModel)]="landlord.name" required maxlength="32">
</div>
<div class="form-group">
<label>{{l("OrganizationName")}}</label>
<input class="form-control" type="email" name="organizationName" [(ngModel)]="landlord.organizationName" required maxlength="500">
</div>
I need to populate organizationName, when I enter value in Name field. 在“名称”字段中输入值时,需要填充organizationName。 How I can do this? 我该怎么做?
You can use ngModelChange
event emitter, like: 您可以使用ngModelChange
事件发射器,例如:
<input #nameInput (ngModelChange)="onNameChange($event)" class="form-control" type="text" name="name" [(ngModel)]="landlord.name" required maxlength="32">
And define onNameChange in your component: 并在组件中定义onNameChange:
public onNameChange(name: string) {
// implement some logic for picking the organization name
// and update the input
this.landlord.organizationName = 'some organization name';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.