在加载内容之前先加载页脚

时间:2018-10-24 04:16:04

标签: angular angular6

在我的应用程序中,页脚在事件加载之前已加载。这些是我尝试过的代码。我在开始时有一个变量设置为false,后来从api加载事件数据时,我将其设置为true。

现在在我的页脚组件中,我设置了ngIf进行检查。

如果我有* ngIf =“ loaded”,则不会显示页脚,并且如果* ngIf =“!loaded”页脚在事件开始前已加载。

有人可以帮助我解决此问题吗?

events.component.ts

export class EventsComponent implements OnInit {

    events = [];
    loaded = false;
    constructor(private _eventService: EventService) { }

    ngOnInit() {
        this._eventService.getEvents()
            .subscribe(
                res => {
                    this.events = res;
                    this.loaded = true;
                    console.log(this.loaded);
                },
                err => console.log(err)
            );
    }
}

footer.component.html

<div class="wrapper" *ngIf="loaded">

0 个答案:

没有答案