

inputValue!: string;
에러안 나서

왜 그러나 어제 작성해본 파일과 비교해 봤더니
객체를 추가하는 배열에 맨마지막에 추가를 어떤 것을 하는 것에 id를 작성을 잘 못 하였음
문제>> id: this.input[length -1].id +1
수정 >> id: this.input[this.input.length-1].id +1
아이디 값도 추가하는 것도 맨마지막 길이의 아이디 값에서 1을 추가 해야 되기 때문에
<input type="text" placeholder="입력" [(ngModel)]="inputValue" /> \
<button (click)="addtodo()">add</button>
@for (addinput of input ; track $index) {
<ul>
<li>
{{ addinput.id }}
{{ addinput.logId }}
</li>
</ul>
}
import { CommonModule } from '@angular/common';
import { Component, OnInit, input } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Title } from '@angular/platform-browser';
interface todos {
id: number;
logId: string;
password: string;
}
@Component({
selector: 'app-study',
standalone: true,
imports: [CommonModule, FormsModule],
templateUrl: './study.component.html',
styleUrl: './study.component.scss',
})
export class StudyComponent {
inputValue: string = '';
input: todos[] = [
{
id: 0,
logId: 'chan',
password: '0222',
},
{
id: 0,
logId: 'chan',
password: '0222',
},
{
id: 0,
logId: 'chan',
password: '0222',
},
];
addtodo() {
this.input.push({
id: this.input[this.input.length - 1].id + 1,
logId: this.inputValue,
password: '0222',
});
this.inputValue = '';
// console.log(this.inputValue);
}
}

이거 작성하는데 30분 정도 걸린듯… 매일 계속 출근해서 이제까지 배운거 계속 쭉 한번 쓰려고한다.