简体   繁体   English

Angular 8 和显示组件的顺序

[英]Angular 8 and order of displaying the components

I have two components that are displayed side by side within home component like so:我有两个组件在 home 组件中并排显示,如下所示:

<app-productList></app-productList>
<app-productGallery></app-productGallery>

If I comment out the second line ( <app-productgallery></app-productGallery> ), the app-productList is displayed instantly, but if I don't (I need both), the gallery gets displayed first and only after all the images in the gallery are loaded/seen, the app-productList gets displayed (meanwhile, the product list is empty).如果我注释掉第二行( <app-productgallery></app-productGallery> ), app-productList会立即显示,但如果我不这样做(我需要两者),画廊会首先显示,而且只有加载/查看图库中的图像,显​​示app-productList (同时,产品列表为空)。 I either want that:我要么想要:

  • both components get displayed at the same time OR两个组件同时显示或
  • productList gets displayed first productList 首先显示

I probably could create a promise or an rxjs subject and tell the app that I want to see the gallery only after product list is displayed and not sooner, but my question is more general - why is this even happening, what principle of execution is this following?我可能可以创建一个 promise 或一个 rxjs 主题并告诉应用程序我只想在显示产品列表后而不是更早地查看图库,但我的问题更笼统 - 为什么会发生这种情况,执行原理是什么下列的?

It seems that you have both component in your app.component.html file like this:您的app.component.html文件中似乎有两个组件,如下所示:

<app-product-gallary></app-product-gallary>
<app-product-list><app-product-list>

Angular Render component exactly based on their order that appears in the .html file. Angular Render 组件完全基于它们出现在.html文件中的顺序。 So, simply change their order in your template file by something like this:因此,只需通过以下方式更改它们在模板文件中的顺序:

<app-product-list><app-product-list>
<app-product-gallary></app-product-gallary>

However if you provide some code we can help you better here as there isn't code here and it's just my guess.但是,如果您提供一些代码,我们可以在这里为您提供更好的帮助,因为这里没有代码,这只是我的猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM