1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Is there a nicer way to populate object? [closed]

Discussão em 'Angular' iniciado por Poczok, Setembro 7, 2025.

  1. Poczok

    Poczok Guest

    I am making a movie ticket reservation project and I am drawing a 5x5 css grid (all the "taken:true" seats turns into red). I need the theatre object immediately (in ngOnInit) to be filled with singleSeat objects with "taken:false" status. This solution looks quite ugly to me, is there a better practice to achive the same result?


    public theatre: IMovieTheatre[] = [];

    const singleSeat: ISeat = {id: null, taken: false};
    const row1: ISeat[] = [];
    const row2: ISeat[] = [];
    const row3: ISeat[] = [];
    const row4: ISeat[] = [];
    const row5: ISeat[] = [];
    row1.push(singleSeat, singleSeat, singleSeat, singleSeat, singleSeat);
    row2.push(singleSeat, singleSeat, singleSeat, singleSeat, singleSeat);
    row3.push(singleSeat, singleSeat, singleSeat, singleSeat, singleSeat);
    row4.push(singleSeat, singleSeat, singleSeat, singleSeat, singleSeat);
    row5.push(singleSeat, singleSeat, singleSeat, singleSeat, singleSeat);
    this.theatre.push({Row1: row1, Row2: row2, Row3: row3, Row4: row4, Row5: row5});

    `

    Continue reading...

Compartilhe esta Página