I'm struggling with project for my postgrad studies. I need to make interactive seats map in Angular with max selection of 9 seats. After looking through my previous classes I was able to make some magic in JS but without max selection (link to codepen below).
HTML code contains huge SVG graphic - you can find it in codepen attached below
CSS
.occupied {
fill: red;
}
.free {
fill: #afafaf;
}
Javascript
const buttonArray = document.querySelectorAll("#seats path");
console.log("query", typeof buttonArray);
var myArray = Array.from(buttonArray);
console.log(myArray);
for (let i = 0; i < myArray.length; i++) {
myArray[i].setAttribute("id", `seat_${i + 1}`);
document.getElementById(`seat_${i + 1}`).addEventListener("click", function() {
if (document.getElementById(this.id).getAttribute("class") == "occupied") {
document.getElementById(this.id).removeAttribute("style");
document.getElementById(this.id).setAttribute("class", "free");
} else {
document.getElementById(this.id).removeAttribute("style");
document.getElementById(this.id).setAttribute("class", "occupied");
}
});
}
I have no clue how to implement this into Angular, or how to even make it simplier. And of course how to make this maximum selection of 9 seats.
I would be grateful for any of your advices and help.