0

So I'm currently learning Angular V14 with Typescript. I have a component which takes an @Input of Task (Task being an interface):

Component:

import { Component, OnInit, Input } from '@angular/core';
import { Task } from 'src/app/models/Task';

@Component({
  selector: 'app-task-item',
  templateUrl: './task-item.component.html',
  styleUrls: ['./task-item.component.css']
})
export class TaskItemComponent implements OnInit {

  @Input() task: Task 

  constructor() {  }

  ngOnInit(): void {
  }

}

My interface

export interface Task {
    id?: number;
    text: string;
    day: string;
    reminder: boolean;
  }

However, I get the following error on the following line:

@Input() task: Task 

Property 'task' has no initializer and is not definitely assigned in the constructor.

How do I actually initialize an interface within the constructor?

Code Ratchet
  • 5,758
  • 18
  • 77
  • 141
  • 1
    this link might help you : - https://stackoverflow.com/questions/49699067/property-has-no-initializer-and-is-not-definitely-assigned-in-the-construc – moh Nov 14 '22 at 05:02

0 Answers0