首先,请确保您在组件的HTML模板中正确绑定了数据。如果您绑定了正确的数据,但是信息仍然不显示,请检查CSS样式是否正确。如果CSS样式是正确的,请尝试使用Angular的ChangeDetection机制手动更新视图。您可以使用以下代码示例:
import { ChangeDetectorRef, Component } from '@angular/core';
@Component({ selector: 'app-sidebar', templateUrl: './sidebar.component.html', styleUrls: ['./sidebar.component.css'] }) export class SidebarComponent { info: any;
constructor(private cdr: ChangeDetectorRef) { }
// call this method to manually update the view updateView() { this.cdr.detectChanges(); } }
在更新信息后,您可以手动调用updateView()方法来更新视图。