我在和安格拉合作,我有一个聊天系统。
当用户发送消息时,将创建li元素:
chat-component.html

<li #ChatListItem *ngFor="let message of messages" class="list-group-item">
    {{message}}
</li>

这意味着在页面加载中,在DOM中还不存在。
我需要对#ChatListItem(即autoscroll)执行一些操作,因此在我的组件中:
#ChatListItem
chat-component.ts
但是当我试图编译时,我得到了一条错误消息:
@ViewChildren('ChatListItem') chatListItem: QueryList<ChatListItem>;
即使我有这个错误,这仍然可以使用error TS2304: Cannot find name 'ChatListItem'.,但是我不能运行任何ng serve。
我想这是因为ng build中不存在#ChatListItem?
我怎样才能做到这一点?

最佳答案

您的元素不是ChatListItem类型,但它只是一个li元素。因此,您需要在li中提供QueryList的类型。

@ViewChildren('ChatListItem') chatListItem: QueryList<HTMLLIElement>

10-06 06:46