app.routes won't recognize my component in Angular

44 views Asked by At

I am new to Angular and after having followed a tutorial, I've decided to experiment a little bit. Today, I encountered this problem:

TS2305: Module '"./components/required-input/required-input.component"' has no exported member 'RequiredInputComponent'.
src/app/app.routes.ts:5:9

I have created a new component and put it in my app.routes.ts (the one in italics is giving me the problem):

import { Routes } from '@angular/router';
import { RoundNumberComponent } from './components/round-number/round-number.component';
import { GuardPageComponent } from './components/guard-page/guard-page.component';
import { guardPageGuard } from './guards/guard-page.guard';
import { RequiredInputComponent } from './components/required-input/required-input.component';

export const routes: Routes = [
  { path: 'round-number', component: RoundNumberComponent },
  { path: 'guard-page', component: GuardPageComponent, canActivate: [guardPageGuard] },
  *{ path: 'required-input', component: RequiredInputComponent }*
];

I do not understand why it is giving me this error. I see no difference in the previous components, and they work fine.

This is my .ts of the component that is giving me problems:

import { Component } from '@angular/core';

import { MatSelectModule } from '@angular/material/select';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';

@Component({
  selector: 'app-required-input',
  standalone: true,
  imports: [
    MatFormFieldModule,
    MatInputModule,
    MatSelectModule,
  ],
  templateUrl: './required-input.component.html',
  styleUrl: './required-input.component.css'
})
export class RequiredInputComponent {

}

How can I solve it?

At first, I tried to go in the component through localhost:4200/componentName, but it didn't work, and after a few minutes the error appeared. I tried to delete the component and generate it again, starting a new server, closing and opening VS Code, but nothing worked.

0

There are 0 answers