Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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 角形管道_Angular - Fatal编程技术网

Angular 角形管道

Angular 角形管道,angular,Angular,我在安格拉尔用烟斗。在本地服务器上工作正常。但是当我使用命令ngbuild--prod时,它会显示错误。 错误:类型“HomeComponent”上不存在属性searchText。 这是我的密码 home.component.html <input [(ngModel)]="searchText" placeholder="search text goes here"> <ul> <li *ngFor="let c of characters | filter

我在安格拉尔用烟斗。在本地服务器上工作正常。但是当我使用命令ngbuild--prod时,它会显示错误。 错误:类型“HomeComponent”上不存在属性searchText。 这是我的密码

home.component.html

 <input [(ngModel)]="searchText" placeholder="search text goes here">
<ul>
  <li *ngFor="let c of characters | filter : searchText">
{{c}}
</li>
</ul>
过滤管

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter'
 })
export class FilterPipe implements PipeTransform {
transform(items: any[], searchText: string): any[] {
if(!items) return [];
if(!searchText) return items;
searchText = searchText.toLowerCase();
return items.filter( it => {
  return it.toLowerCase().includes(searchText);
  });
  }
 }
app.module.ts

 import { BrowserModule } from '@angular/platform-browser';
 import { NgModule } from '@angular/core';
 import { FormsModule } from '@angular/forms';
 import {RouterModule,Routes} from '@angular/router';
 import { AppComponent } from './app.component';
 import { HomeComponent } from './home/home.component';
 import { FilterPipe } from './filter.pipe';


@NgModule({
 declarations: [
 AppComponent,
 HomeComponent,
 FilterPipe
],
 imports: [
  BrowserModule,
  FormsModule,
  RouterModule.forRoot([
  {path:'home',component:HomeComponent},
  {path:'',redirectTo:'home',pathMatch:'full'},
   ])
 ],
 providers: [],
 bootstrap: [AppComponent]
  })

 export class AppModule { }
没有变量名 在home.component.ts的ts文件中搜索文本

所以在您的ts文件中添加

searchText: string;

您必须在
home.component.ts中初始化
searchText
,如下所示
searchText:string=''
搜索文本:字符串
searchText: string;