Angular Not Detecting TypeScript in File

I’m trying to create a todo list in Angular. I have a todos component and a separate folder with a Todos.ts file. I have an array in the todos component that follows a model written in the Todos.ts file. I’m trying to have specific types for my component but when I try to use the Todos.ts file in the component I keep getting this error. Do I need to install something for Angular to detect the typescript class? I’m having trouble understanding why I’m getting an error for the specified types in the Todos.ts file. I thought Angular is supposed to auto detect typescript.

Here is my code:
Todo component

import { Component, OnInit } from '@angular/core';
import {Todo} from './../../models/Todo';

@Component({
  selector: 'app-todos',
  templateUrl: './todos.component.html',
  styleUrls: ['./todos.component.scss']
})
export class TodosComponent implements OnInit {

  todos: Todo[];

  constructor() { }

  ngOnInit(): void {
    this.todos=[
      {
        content: "first todo",
        completed: false
      },
      {
        content: "second todo",
        completed: true
      }
    ]
  }
}

Todo.ts class (in seperate folder)

export class Todo{
    content:string;
    completed:boolean;
}

I’m trying to follow along with this tutorial: https://www.youtube.com/watch?v=i7KaVFOXNUQ

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.