[英]Angular 2: Component doesn't render
I am using a custom component in angular 2 but it doesn't render . 我在angular 2中使用了自定义组件 , 但未渲染 。 I cannot find out why it doesn't render.
我不知道为什么它不呈现。
Attempt 1: This is the html page where the component is used ( doesn't work ): 尝试1:这是使用组件的html页面( 不起作用 ):
<div class="container-fluid container-content" *ngIf="project">
<div class="projectdetail" style="background: green">
<img [src]="project.img" [alt]="project.name" style="height: 150px" />
<h2>{{project.name}}</h2>
<div>
<carousel interval="5000" noWrap="false">
<slide *ngFor="let slidez of slides; let index=index">
<img [src]="slidez.image" class="carouselimg" />
<div class="carousel-caption">
<h4>Slide {{slidez.id}}</h4>
<p>{{slidez.text}}</p>
</div>
</slide>
</carousel>
</div>
<p>{{project.description}}</p>
</div>
<!--hidden-mm hidden-sm hidden-xs-->
<div class="projects" style="background: red">
qsdfqsdfqsdf
<projectlist></projectlist>
</div>
</div>
Attempt 2: When I put the projectlist tag inside the div, then it actually work . 尝试2:将projectlist标记放入div时,它实际上可以工作 。 Weird?
奇怪的?
<div class="container-fluid container-content" *ngIf="project">
<div class="projectdetail" style="background: green">
<img [src]="project.img" [alt]="project.name" style="height: 150px" />
<h2>{{project.name}}</h2>
<div>
<carousel interval="5000" noWrap="false">
<slide *ngFor="let slidez of slides; let index=index">
<img [src]="slidez.image" class="carouselimg" />
<div class="carousel-caption">
<h4>Slide {{slidez.id}}</h4>
<p>{{slidez.text}}</p>
</div>
</slide>
</carousel>
</div>
<p>{{project.description}}</p>
<!-- ADDED THIS-->
<projectlist></projectlist>
</div>
<!--hidden-mm hidden-sm hidden-xs-->
<div class="projects" style="background: red">
qsdfqsdfqsdf
<projectlist></projectlist>
</div>
</div>
Screenshot ( Shows only one time (the second projectlist and not the first) ) 屏幕截图( 仅显示一次(第二个项目列表,而不是第一个) )
I use the component somewhere else and there it actually works correctly, so don't know what the problem is. 我在其他地方使用了该组件,并且在那里实际上可以正常工作,所以不知道问题出在哪里。
Here is a github link: Github 这是github链接: Github
If you need extra info or code just ask. 如果您需要其他信息或代码,请询问。
I investigated a bit this issue and found that the problem occurs only in chrome browser. 我对此问题进行了调查,发现该问题仅在chrome浏览器中发生。
Chrome sends a request from ProjectListComponent
with strange headers Chrome从
ProjectListComponent
发送带有奇怪标题的请求
As workaround you can solve it by the trick 作为解决方法,您可以通过技巧解决
projectlist.component.ts projectlist.component.ts
ngOnInit() {
setTimeout(() => this.getProjects(), 0);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.