【问题标题】:attaching two input placeholder in one placeholder在一个占位符中附加两个输入占位符
【发布时间】:2018-03-08 18:43:03
【问题描述】:

目前我在一个导航项目中工作,我从用户那里得到两个输入,分别是经度和纬度。输入应该一个接一个地给出。我想要的是将这两个输入作为一个用逗号分隔,这样如果我输入喜欢 41.23, 34.32 ,到经度41.23,纬度34.32的位置。

我现在的代码是:

<div *ngIf="data.mod=='goLocation'" class="panel-body">
    <form #f="ngForm" (ngSubmit)="go(f.value); f.reset();" class="settings-form">
      <table>
        <tr>
          <td>
            <mat-form-field>
              <input matInput placeholder="Enlem(Y)" name="lat" id="lat" #lat="ngModel" ngModel required>
              <mat-error *ngIf="lat.touched && lat.invalid">
                <div *ngIf="lat.errors.required">Bu alanı boş geçemezsiniz.</div>
              </mat-error>
            </mat-form-field>
          </td>
          <td>
            <mat-form-field>
              <input matInput placeholder="Boylem(X)" name="lon" id="lon" #lon="ngModel" ngModel                         required>
              <mat-error *ngIf="lon.touched && lon.invalid">
                <div *ngIf="lon.errors.required">Bu alanı boş geçemezsiniz.</div>
              </mat-error>
            </mat-form-field>
          </td>
        </tr>
      </table>
      <button [disabled]="!f.valid" class="btn btn-outline-primary">Git</button>
    </form>
  </div>

【问题讨论】:

  • 您尝试过但失败了吗?您可以发布您的代码示例吗?
  • 我正在考虑找到一种方法,如果可以将两个输入和两个不同的 id 连接在一起。

标签: javascript html css angular bootstrap-4


【解决方案1】:

只是在(更改)中进行拆分

<input #latlon (change)=changeLatLon(latlon.value)>

changeLatLon(value:any)
{
    let latlog=value.split(',');
    this.lat=latlon[0];
    this.lon=latlon.length>1?latlog[1]:0; //if latlon haven't a ",",
                                          //   latlong.length=1
}

【讨论】:

  • split()方法用于将一个字符串拆分成一个子字符串数组,
【解决方案2】:

感谢 Eliseo,下面的代码完成了这项工作。

export class LocationComponent {

  lat;
  lon;

  constructor() {
  }

  go(form) {
    form.lat=this.lat;
    form.lon=this.lon
    this.mapService.esri.go(form.lon, form.lat);
    this.dialogRef.close();
  }
  changeLatLon(value:any){
    let latlog=value.split(',');
    this.lat=latlog[0];
    this.lon=latlog.length>1?latlog[1]:0; //if latlon haven't a ",",
                                          //   latlong.length=1 
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-23
    • 2020-04-12
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2021-05-17
    相关资源
    最近更新 更多