While run my angular project got
Property ' ' has no initializer and is not definitely assigned in the constructor
near all variables inside modal. I am new in Angular. I am stuck due to this error and I Googled for this error but no solution found. My Node version is 16.14.0
and my Npm version is 8.3.1
.
Here down is my code:
Modal
export class Todo{
// got error in below variables
sno: number
title: string
desc: string
active: boolean
}
todos.component.ts
import { Component, OnInit } from '@angular/core';
import { Todo } from '../../Todo';
@Component({
selector: 'app-todos',
templateUrl: './todos.component.html',
styleUrls: ['./todos.component.css']
})
export class TodosComponent implements OnInit {
todos!: Todo[];
constructor() {
this.todos = [
{
sno: 1,
title: "Title1",
desc: "description1",
active: true
},
{
sno: 2,
title: "Title2",
desc: "description2",
active: true
},
{
sno: 3,
title: "Title3",
desc: "description3",
active: true
}
]
}
ngOnInit(): void {
}
}
HTML
<div class="container-fluid">
<ul *ngFor="let todo of todos">
<li>{{todo.sno}} - {{todo.title}} - {{todo.desc}} - {{todo.active}}</li>
</ul>
</div>