Error messages are displayed for attribute directives even in a freshly generated Angular project

I am experiencing an issue with a newly created Angular Project in Visual Studio Code where attribute directives like [ngClass], [ngSwitch], and others are showing errors in the .html file. Here is the standard app.component.html file created as part of "ng new".

Link to app.component.html file

In app.module.ts, I have imported CommonModule as suggested on various online sites as shown below:

Sample code in app.module.ts

After adding it, the error in the .html file still persists. However, this error does not affect the functionality when running the ng serve command as the page displays correctly in the browser.

I have searched online for solutions but could not find any similar issues reported. Below is the Angular version information for my workspace:

Angular CLI version details

Since I am new to Angular, I have only tried out some suggestions found online such as importing CommonModule in app.module.ts. I have spent nearly 3 days researching and reading up on this issue without much success. I also attempted to uninstall and reinstall Angular Language Service, but that did not resolve the problem.

I would greatly appreciate any help or insights from fellow developers. Thank you in advance!

[Updated with code snippets]

Partial code snippet from app.component.html file:

<div class="terminal" [ngSwitch]="selection.value">
      <pre *ngSwitchDefault>ng generate component xyz</pre>
      <pre *ngSwitchCase="'material'">ng add @angular/material</pre>
      <pre *ngSwitchCase="'pwa'">ng add @angular/pwa</pre>
      <pre *ngSwitchCase="'dependency'">ng add _____</pre>
      <pre *ngSwitchCase="'test'">ng test</pre>
      <pre *ngSwitchCase="'build'">ng build</pre>
  </div>

Snippet from app.module.ts file:

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CommonModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Angular CLI Version:

Angular CLI: 16.1.4
Node: 18.16.1
Package Manager: npm 9.5.1
OS: win32 x64

Angular: 16.1.6
Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1601.4
@angular-devkit/build-angular   16.1.4
@angular-devkit/core            16.1.4
@angular-devkit/schematics      16.1.4
@angular/cli                    16.1.4
@schematics/angular             16.1.4
rxjs                            7.8.1
typescript                      5.1.6

Error message received:

(directive) NgSwitch
Can't bind to 'ngSwitch' since it isn't a known property of 'div'.ngtsc(-998002)
app.component.ts(2, 26): Error occurs in the template of component AppComponent.

[Update - Comparison with my old Angular test project]

It would be easier to illustrate the differences through images rather than code. I suspect there may be version compatibility issues as removing CommonModule from my older test project results in a different error compared to the one in the newer version. Any clarification on this matter would be highly appreciated.

Comparison between Angular versions 16.1.6 and 14.1.1

As I am not an expert in Angular, I am seeking assistance here. Thank you once again for your help!

Answer №1

Successfully identified the issue as stemming from Angular Language Service. Outlined below are the steps taken to resolve it: -

  1. Updated Visual Studio Code to version 1.80.1
  2. Uninstalled and re-installed the Angular Language Service Extension

Following these actions, attribute directives like [ngClass], [ngSwitch], etc., no longer display errors in the .html file. Further verification was conducted by removing CommonModule from app.module.ts file, resulting in the same error message as observed in my test project with Angular version 14.1.1

Hoping this information proves beneficial for others facing a similar issue. Thank you and have a wonderful day!

A special thanks to @Rituparna Warwatkar for pointing out the importance of VS Code, prompting me to focus my efforts in this direction.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing RTKQuery queryFn in TypeScript: A comprehensive guide

Important update: The issue is now resolved in RTKQuery v2 after converting to TypeScript. See the original question below. Brief summary I am encountering an error while trying to compile the TypeScript code snippet below. Tsc is indicating that the r ...

I'm working on an Angular2 project and I'm looking for a way to concatenate all my JavaScript files that were created from TypeScript in Gulp and then include them in my index

How can I concatenate all JavaScript files generated from typescript in my Angular2 project with Gulp, and then add them to my index.html file? I am using Angular2, typescript, and gulp, but currently, I am not concatenating the javascript files it genera ...

Save the resolved value of an Observable for repeated usage in a Template

In my Angular template, I am aiming to accomplish something along these lines: <div *ngIf="let resolved = (observable$ | async)"> <span>{{resolved.property1}}</span> <span>{{resolved.property2}}</span> <span>{{res ...

Finding the specific type within a union based on its field type

I am trying to implement a function sendCommand that returns a value of type specified by the union InputActions, selected based on the action_id type. Below is my code snippet: interface OutputAction1 { command: 'start', params: string; } i ...

Creating a TypeScript type or interface that represents an object with one of many keys or simply a string

I am tasked with creating an interface that can either be a string or an object with one of three specific keys. The function I have takes care of different errors and returns the appropriate message: export const determineError = (error: ServerAlerts): ...

Exploring the weather API integration with Angular 4

I've embarked on a journey to teach myself Angular4 by creating a Weather app. However, I'm facing challenges in connecting the API. Despite consulting various resources, such as: https://medium.com/craft-academy/connecting-an-api-to-an-angular- ...

Shortcut in Visual Studio Code for PHP code block

Is there a way to create a basic PHP block in Visual Studio Code, similar to how it's done in Sublime Text using the shortcut php + Tab? In Sublime Text, typing php followed by pressing Tab automatically generates the PHP block. However, I'm una ...

receiving login failure alert upon attempting to sign in

After implementing a login page in Angular and connecting it to the database using an API, I encountered an issue. When entering incorrect credentials in Google Chrome, I receive a sign-in alert with reference to my API source located at http://staging.xyz ...

FilterService of PrimeNg

Looking for assistance with customizing a property of the p-columnFilter component. I have managed to modify the filter modes and customize the names, but I am having trouble with the no-filter option. Has anyone found a solution for this? this.matchMo ...

having difficulties in separating the mat-table header

It may seem like a basic question, but I'm having trouble figuring it out. I'm not sure if this requires a CSS change or something else. I'm looking to add a divider between my table header similar to the one highlighted in the screenshot be ...

Trouble arises with tap operator's output in RxJS

I'm puzzled by the results of the code below. According to the take(3) function, processing should stop after rendering 10, but I'm still seeing 5, 6, and 9 from the tap operator. Please see the output and code snippet below for reference. Tapp ...

The modeless service in FeathersJS is failing to provide the correct JSON response

Could someone please explain to me how the service creation process works? I have been struggling for hours trying to receive JSON objects that do not meet my expectations. After much trial and error, I have come up with the following code for the before h ...

When attempting to redirect to the home page in Angular 6, the page successfully redirects but fails to load properly

I am new to using angular. Recently, I converted a large project from html/css/php/js to twig/slim, and switched the hosting platform from apache2/sql to s3 buckets/lambda apis. While I have successfully converted smaller projects to angular without any i ...

Difficulty encountered while trying to run the ngx-admin dashboard designed for Angular

I encountered some issues during the installation of node modules. Can someone please assist me with this? Angular CLI: 13.3.0 Node: 16.14.2 Click here to view the list of problems Any help would be greatly appreciated. ...

How to export a class from a function in Typescript

Here is the objective I'm aiming to accomplish: loadDependency(function(dep){ //error, can't use export within a function export class MyClass { myF(){ dep.myStuff(); } } }); I am restricted to creati ...

Issue with Nativescript + Angular project: A critical error has occurred - Module not found: '@schematics/angular/utility/parse-name'

I'm diving into nativescript development for the first time and I'm attempting to create a new component using this command: ng g c component-name The error message that's popping up reads: An unhandled exception occurred - Cannot find modu ...

Discovering the number of items that have been filtered in isotope-layout using React and Typescript

Currently, I am utilizing the isotope-layout library within a React (Typescript) project. Although I have successfully implemented filtering on my page, I am unsure of how to retrieve the count of the filtered items. Upon loading the page, Isotope is init ...

Testing the Child Component's EventEmitter Functionality

In my child component, there is an event emitter that sends a boolean value when the style changes in the parent component: export class ExampleComponent implements OnInit, OnChanges { @Output() statusEvent = new EventEmitter<boolean>(); getS ...

How can I place an Object in front of an Array in JavaScript?

Currently, I am working on an Angular project where I need to modify a JSON array in order to display it as a tree structure. To achieve this, the objects in the array must be nested within another object. Desired format / output: this.nodes = [ { id ...

Angular jsonp.get request was denied despite receiving a status code of 200 indicating success

I have been attempting to access my basic web API created in Jersey, which returns the following data: [ { "id": 1, "name": "Facebook", "userName": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4 ...