I am building an angular application about some projects I did. I have a detail page that shows the detail of a project.
The problem: When I go to the project detail page, everything is correct. But when I switch the project variable (by using the navigation I have on the page) the dependency component doesn't update, they don't get the correct project ID.
The projectdetail.html page that contains all the components:
<div class="container-content" *ngIf="project">
<div class="projectdetail">
<div class="thumbnail header">
<img [src]="project.img" [alt]="project.name" class="projectImage" />
<div>
<h2>{{project.name}}</h2>
<!--The programming component that you can see in the image-->
<programming-languages [ids]="project.languages"></programming-languages>
</div>
</div>
<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>
<div class="thumbnail detail">
<p>{{project.description}}</p>
</div>
</div>
<div class="projects hidden-mm hidden-sm hidden-xs">
<projectsidelist [notShowId]="selectedProjectId"></projectsidelist>
</div>
</div>
The language component code:
import { Component, Input, OnInit } from '@angular/core';
import { ProgrammingLanguagesService } from '../services/programminglanguages.service';
import { ProgrammingLanguage } from '../models/programmingLanguage';
@Component({
selector: 'programming-languages',
templateUrl: 'app/components/programminglanguages.component.html',
providers: [ProgrammingLanguagesService]
})
export class ProgrammingLanguages implements OnInit {
@Input()
ids: number[];
programmingLanguages: ProgrammingLanguage[];
constructor(private programmingLanguagesService: ProgrammingLanguagesService) {
}
getProgrammingLanguages() {
this.programmingLanguagesService.getProgrammingLanguages().subscribe(programmingLanguages => {
var result: ProgrammingLanguage[] = [];
this.ids.forEach((key: number) => {
programmingLanguages.forEach((programmingLanguage: ProgrammingLanguage) => {
if (programmingLanguage.id == key)
{
result.push(programmingLanguage);
}
})
})
this.programmingLanguages = result;
});
}
ngOnInit() {
setTimeout(() => this.getProgrammingLanguages(), 0);
}
}
The programming language html:
<div class="languageoverlay">
<span *ngFor="let programmingLanguage of programmingLanguages; let lastElement = last">
<img [src]="programmingLanguage.img" [alt]="programmingLanguage.name" />
<span [hidden]="lastElement" class="languageseperator">+</span>
</span>
</div>
If you need extra code please ask or refer to the github
Github containing All the code
Explanation when you run the github: go to http://localhost:3000/#/projectdetail/5 and click another project on the left bar. Then you see the issue!

