更新我要显示的项目列表时,用ngFor动态添加组件不起作用

时间:2019-02-02 23:05:02

标签: angular typescript

我正在尝试使组件成角度地向其容器之一动态添加组件。在没有def build_placements(shoes): """Return a dictionary where each key is a company, and each value is a list of placements by people wearing shoes made by that company. >>> result = build_placements(['Saucony', 'Asics', 'Asics', 'NB', 'Saucony', 'Nike', 'Asics', 'Adidas', 'Saucony', 'Asics']) >>> result == {'Saucony': [1, 5, 9], 'Asics': [2, 3, 7, 10], 'NB': [4], 'Nike': [6], 'Adidas': [8]} True """ empty_dict = {} for item in shoes: indices = [i for i, x in enumerate(shoes) if x == item] for value in item: value += 1 empty_dict[item] = indices return empty_dict if __name__ == '__main__': import doctest doctest.testmod() 的情况下,使用NameError: name 'result' is not defined 可以达到完美的效果。如果我在构造对象之前给出了要显示的项目列表,则效果很好。现在,我最初有一个空列表,其中将添加,删除和更新项目。我希望该列表中的组件能够反映出该列表中的更改。

这是我当前的代码:

HTML:

ngFor

组件

DynamicComponentLoader

不幸的是,当我向列表中添加元素时,这些组件并未添加到HTML中。除了必须使用<div id = "simple_pov_games_container"> <app-games-card-view *ngFor = "let gameCard of simplePOVGames; let i = index" [gameCard] = "gameCard"> <p>Hello</p> </app-games-card-view> </div> 之外,还有其他方法吗?

0 个答案:

没有答案