I have multiple slides and based on those slides i want to make links that go to the slides but i want the generation of the navigation links to go automatic and its not working
im kinda new at angular and typescript so im at a loss
this is the generation of the links:
export class LinksComponent implements OnInit {
links:Link[];
constructor(private sS:SlidesService) { }
ngOnInit() {
let slides = this.sS.getSlides();
for (let s of slides) {
let obj = {} as Link;
obj.name = s.name;
obj.href = "#" + s.name;
obj.selected = false;
this.links.push(obj);
}
}
}
sS is a service and the getSlides calls this function:
getSlides() {
return [
{
name: "home",
index: 1,
selected:true,
background:"url(bg_home.jpg)"
},
{
name: "me",
index: 2,
selected:true,
background:"url(bg_me.jpg)"
},
{
name: "projects",
index: 3,
selected:true,
background:"url(bg_projects.jpg)"
}
]
}
i get this error ERROR typeError: cannot read property 'push' of undefined even though i defined links(the array im trying to push objects in) now i have looked for some answers but im at a loss. any help would be much appreciated
I want it to work so my links get dynamically made from the amount of slides with the corresponding name and stuff.