试图将数组传递给@Input()参数,但根本不显示。
<ng-container *ngIf = "searchResults != undefined">
<searchresult *ngFor = "let result of searchResults;"
[title] = 'result.title'
[authorName] = 'result.authorName'
[content] = 'result.content'
[tagList] = "result.tagList"
></searchresult>
</ng-container>
<p *ngIf = "searchResults == undefined">loading...</p>
然后在搜索结果中我得到
<div class = "search-result">
<div class = 'result-top-section'>
<div class = 'author-profile'>
<img width = '70' height = '70' class = 'profile-icon' src= '/images/ogpfp.png'/>
<p>{{ authorName }}</p>
</div>
<div class = 'content'>
<h2>{{ title }}</h2>
<p>{{ content }}</p>
</div>
</div>
<div class = 'result-tag-row'>
<tag *ngFor = "let tag of tagList;" [tagName] = 'tag'></tag>
</div>
这是SearchResultComponent类
@Component({
selector: 'searchresult',
templateUrl: './searchResult.component.html',
styleUrls: ['./searchResult.component.css']
})
export class SearchResultComponent implements ISearchResult{
@Input()
title: string;
@Input()
authorName: string;
@Input()
content: string;
@Input()
tagList: string[];
}
https://snag.gy/Nt4JIo.jpg 这是数组,因此您可以看到标记列表已填充
https://snag.gy/SIX0Gs.jpg 这就是html的输出,如您所见,除了标签列表
,每个输入属性都已设置如果有什么让我知道的话,我可能在这里丢失了一些东西。预先感谢。
答案 0 :(得分:1)
如评论中所述,在将标签列表绑定到result.tagList
组件的result.tags
输入时,您输入了错字(tagsList
而不是searchresult
。 / p>
要解决此问题,您必须将绑定更改为[tagList] = "result.tags"
。