C#C
C#2w ago
UÉSLEI

The .NET Angular project is already starting with problems.

I just created an Angular project with ASP.NET using Visual Studio and it didn't work. It returned the following error in my app.ts file inside angularwithasp.client (AngularWithASP is the name of my project):

Could not find name 'OnInit'.ts(2304)
Could not find name 'WeatherForecast'.ts(2304)
Could not find name 'WeatherForecast'.ts(2304)

I used AI to investigate why the error was occurring and it told me to add the interface:

// Define the WeatherForecast interface used by the component
interface WeatherForecast {
date: string; // ISO date string
temperatureC: number;
temperatureF?: number; // optional if not provided by backend
summary?: string; // optional description
}

It actually worked, but I don't know how. Can someone help me? Is this a makeshift solution, or can I leave it as is, and why doesn't it work without it?
image.png
image.png
Was this page helpful?