传递给Angular2组件的字符串始终未定义

String passed to Angular2 Component is always undefined

本文关键字:字符串 未定义 组件 Angular2      更新时间:2023-09-26

当我将字符串传递到组件的@Input()时,它总是未定义的。

这是我在数组中循环并将字符串传递给组件的地方

https://github.com/davidhoeck/ng2-realtime-chat/blob/master/src/client/app/%2Bmessaging-page/messaging-page.component.html

这是我的组件,我试图从通过的字符串中获得值。

https://github.com/davidhoeck/ng2-realtime-chat/blob/master/src/client/app/chat-window-component/chat-window-component.component.ts

如果有人能解决我的问题就太好了。

问题在于发送字符串的方式"default"被评估为一个变量,由于它不存在于控制器中,它将评估为未定义

相反,添加使用单引号来表示模板中的字符串。

<chat-window [groupid]="'default'"></chat-window>

你可以在这个小例子中看到这个问题。