angular - 如何将值传递给@Input Angular 8
问题描述
我想通过服务传递价值
getSearchChange(event: string): void {
this.searchChange.emit(event);
}
在我的组件中,我有
@Input() set search(newSearch: string) {
if (newSearch !== this.query) {
this.query = newSearch;
}
}
我的看法
<div *ngFor="let pokemon of pokemons.results | search: query">...
但我收到错误
如何通过服务将价值传递给“搜索”?
解决方案
在角度你需要使用输入作为属性你需要在你的html中这样做
<div *ngFor="let pokemon of pokemons.results" [search]="query" >...
在你的组件中
@Input() search: T;
这T
是类型以获取更多详细信息,请查看https://angular.io/api/core/Input
推荐阅读
- android - 如何将按钮插入导航工具栏
- apache-kafka - 在 Kafka 中,无法使用 kafka-consumer-groups.sh 创建新的消费者
- javascript - JavaScript split() 使用一个公共字符,然后 join() 使用不同的字符
- xslt - xsl:choose 找到元素的第一个位置,但不是第二个
- windows - 如何找到我的 Windows 系统的外部 IP?
- amazon-web-services - 为 Kubernetes HA 集群选择 AWS 负载均衡器
- windows - Winginx 停止在 Windows 10 上运行
- android - 如何在android studio中将应用程序启动器图标从方形更改为圆形
- c# - 来自 .NET Core 程序的控制台访问在 PowerShellISE 提示符下运行
- wcf - 检测 WCF 中的断开连接