过滤特定数据并获取错误无法绑定到“ ngModel”

时间:2018-10-22 04:56:46

标签: angular filter pipe angular-ngmodel

我尝试使用管道过滤产品(如果没有从列表中选择的过滤器,我将显示所有产品) 但是我遇到了错误。为什么?

<h2>store</h2>
    <select [(ngModel)]="selectedOption" name=Gender>
      <option *ngFor="let g of GenderFilter">{{g.DisplayText}}</option>
    </select>
    <select>
        <select [(ngModel)]="selectedOptionPrice" name=Price>
      <option *ngFor="let p of PriceFilter">{{p.DisplayText}}</option>
    </select>
    <tr *ngFor="let P of products | filer : Gender | orderBy: 'GenderFilter'">
      <td>{{p.DisplayText}}</td>
    </tr>
    <tr *ngFor="let P of products | filer : Price | orderBy: 'PriceFilter'">
      <td>{{p.DisplayText}}</td>
    </tr>
    <ul>
      <li *ngFor="let store of stores">
        <ul>
          <li *ngFor="let product of store.Products">
              <img src={{product.ProductImage}}>
              <p>store: {{ store.StoreName }}</p>
              <p>Product Price: {{ product.Price | currency}}</p>
            <p>Product Title: {{ product.ProductTitle }}</p>
          </li>
        </ul>
      </li>
    </ul> 

1 个答案:

答案 0 :(得分:1)

可能的原因可能是 缺少FormsModule,因此将其添加到您的模块中,

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
    imports: [
        FormsModule      
    ]

或 在选择中检查[(ngModel)]的语法/拼写