Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用ngModel对值进行一般绑定_Angular_Angular Ngmodel_Angular Pipe - Fatal编程技术网

Angular 使用ngModel对值进行一般绑定

Angular 使用ngModel对值进行一般绑定,angular,angular-ngmodel,angular-pipe,Angular,Angular Ngmodel,Angular Pipe,我刚刚学习Angular 2,我一直无法解决的一个问题是使用ngModel创建表单,而不静态指定绑定到的属性的名称 我不确定克服这个问题的机制(尽管我确信它已经足够普遍),也不确定它在社区中是如何被提及的 “我的模板”确实显示键和值,但不反映保存时的更新。似乎以动态方式引用属性会导致绑定丢失。(是否在管道化数据之前评估绑定属性?) 这就是我被困的地方: 模板: <table class="table table-responsive"> <tr *ngFor="let pr

我刚刚学习Angular 2,我一直无法解决的一个问题是使用ngModel创建表单,而不静态指定绑定到的属性的名称

我不确定克服这个问题的机制(尽管我确信它已经足够普遍),也不确定它在社区中是如何被提及的

“我的模板”确实显示键和值,但不反映保存时的更新。似乎以动态方式引用属性会导致绑定丢失。(是否在管道化数据之前评估绑定属性?)

这就是我被困的地方:

模板:

<table class="table table-responsive">
  <tr *ngFor="let prop of account | keyValues">
    <td>{{ prop.key }}</td>

    // Problem here:
    // if I have [(ngModel)]="prop.key", it only displays the keys
    // if I sub in a static attribute e.g. [(ngModel)]="account.accountName" it works
    <td><input name="{{prop.key}}"  [(ngModel)]="prop.value" /></td>
  </tr>
</table>
组成部分:

  ... boiler plate ...

  save(): void {
    this.accountsService.update(this.account)
      .then(() => this.goBack());
  }

  ...

答案是使用Angular's

您还可以利用某些库,如PrimeFaces的PrimeNG的editable datatable,这是我极力推荐的

  ... boiler plate ...

  save(): void {
    this.accountsService.update(this.account)
      .then(() => this.goBack());
  }

  ...