Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Can';t读取组件中的变量';s的html文件_Angular - Fatal编程技术网

Angular Can';t读取组件中的变量';s的html文件

Angular Can';t读取组件中的变量';s的html文件,angular,Angular,我试图显示一个数组的数据(在chat.component中填充) ..inchat.component.html <div class="matchesList" *ngFor="let match of matchesList"> <p>{{match}}</p> </div> 为什么在chat.component.html中无法访问matchesList的数据 谢谢大家! 之所以发生这种情况,是因为用于调用This.chatComp.

我试图显示一个数组的数据(在
chat.component
中填充)

..in
chat.component.html

<div class="matchesList" *ngFor="let match of matchesList">
    <p>{{match}}</p>
</div>
为什么在
chat.component.html
中无法访问
matchesList
的数据


谢谢大家!

之所以发生这种情况,是因为用于调用
This.chatComp.loadMatches()
的实例与用于呈现以下模板的实例不同-

chat.component.html

<div class="matchesList" *ngFor="let match of matchesList">
    <p>{{match}}</p>
</div>

发生这种情况的原因是,用于调用
This.chatComp.loadMatches()
的实例与用于呈现以下模板的实例不同-

chat.component.html

<div class="matchesList" *ngFor="let match of matchesList">
    <p>{{match}}</p>
</div>

这不是您使用组件的方式,您不需要将其添加到组件
提供程序:[……]
。这是用于服务的。@marshalllegend感谢您的回答,我能做什么?中的回答应该有助于澄清如何在子组件中调用方法。@marshalllegend非常感谢!它现在运行良好,我需要进入更多的文档我的头!再次谢谢,很高兴听到这个消息!这不是您使用组件的方式,您不需要将其添加到组件
提供程序:[……]
。这是用于服务的。@marshalllegend感谢您的回答,我能做什么?中的回答应该有助于澄清如何在子组件中调用方法。@marshalllegend非常感谢!它现在运行良好,我需要进入更多的文档我的头!再次谢谢,很高兴听到这个消息!
chat.component.html

<div class="matchesList" *ngFor="let match of matchesList">
    <p>{{match}}</p>
</div>
1. Chat Component.ts/.html
2. Home component.ts/.html
3. The parent [if any] which holds those two components [If not then let us know how those are rendered [i.e. Parent/Child?]