I have:
export class Column {
constructor(public name: string, public tasks: string[]) {} }
and
import { Column } from './column.model';
export class Board {
constructor(public name: string, public columns: Column[]) {}}
Here is my typescript code:
import { Component, OnInit } from '@angular/core';
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
import { Board } from 'src/app/models/board.model';
import { Column } from 'src/app/models/column.model';
@Component({
selector: 'app-main-view',
templateUrl: './main-view.component.html',
styleUrls: ['./main-view.component.scss']
})
export class MainViewComponent implements OnInit {
newcolumn: string;
constructor() { }
board: Board = new Board('Test Board', [
new Column('First', [
"one",
"two"
])
]);
ngOnInit() {
}
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex);
}
}
addColumn() {
this.board.columns.push(this.newcolumn);
}
}
Error: Property 'name' does not exist on type 'Column[]
I have trouble with adding a function that adds a new column to my board. There is also a bug when using board.column.name. Please help. I've been trying to do this for several hours.