无法在Angular中读取组件的html文件中的变量

时间:2019-06-13 15:18:30

标签: angular

我正在尝试显示数组的数据(填充在In file included from include/linux/linkage.h:6:0, from include/linux/preempt.h:9, from include/linux/spinlock.h:50, from include/linux/mmzone.h:7, from include/linux/gfp.h:5, from include/linux/mm.h:9, from mm/ksm.c:18: include/linux/export.h:57:2: error: expected ',' or ';' before 'extern' extern typeof(sym) sym; \ ^ include/linux/export.h:69:2: note: in expansion of macro '__EXPORT_SYMBOL' __EXPORT_SYMBOL(sym, "") ^ mm/ksm.c:1830:1: note: in expansion of macro 'EXPORT_SYMBOL' EXPORT_SYMBOL(ksm_run_change); ^ scripts/Makefile.build:257: recipe for target 'mm/ksm.o' failed make[1]: *** [mm/ksm.o] Error 1 Makefile:938: recipe for target 'mm' failed make: *** [mm] Error 2 中。)

#define __EXPORT_SYMBOL(sym, sec)                               \
        extern typeof(sym) sym;                                 \
        __CRC_SYMBOL(sym, sec)                                  \
        static const char __kstrtab_##sym[]                     \
        __attribute__((section("__ksymtab_strings"), aligned(1))) \
        = VMLINUX_SYMBOL_STR(sym);                              \
        extern const struct kernel_symbol __ksymtab_##sym;      \
        __visible const struct kernel_symbol __ksymtab_##sym    \
        __used                                                  \
        __attribute__((section("___ksymtab" sec "+" #sym), unused))     \
        = { (unsigned long)&sym, __kstrtab_##sym }

.. in chat.component ..

public matchesList = [];

loadMatches() {
...
    if (result.success) {
      this.matchesList = result.matches_list.split(',');
      console.log(this.matchesList);
    }
}

..没有任何运气!

chat.component.html告诉我该数组已正确填充:<div class="matchesList" *ngFor="let match of matchesList"> <p>{{match}}</p> </div>

从另一个组件console.log()中调用

(3) ["3", "5", "6"]

loadMatches()

为什么home.component中无法访问import { ChatComponent } from '../chat/chat.component'; @Component({ providers: [ChatComponent], ... }) loadChatViewData() { this.chatComp.loadMatches(); } <a class="nav-link" (click)="loadChatViewData()"></a> 的数据?

谢谢!

1 个答案:

答案 0 :(得分:1)

之所以发生这种情况,是因为您用来调用div4的实例与用于渲染以下模板的实例不同-

this.chatComp.loadMatches()

您使用过chat.component.html <div class="matchesList" *ngFor="let match of matchesList"> <p>{{match}}</p> </div> ,它将为您提供与用于渲染的实例不同的实例。

如果您可以共享以下组件的html / .ts文件以及将组件放置在用户界面中的代码[html],我们将为您提供进一步的帮助-

providers: [ChatComponent]