After upgrading to Angular 12, although I have all the required code in app.module.ts, all the material tags are not recognized: for example, for mat-checkbox, I have the following in app.module.ts
import { MatCheckboxModule } from '@angular/material/checkbox';
@NgModule({
imports: [
BrowserModule,
MatCheckboxModule,
and at execution:
'mat-checkbox' is not a known element:
And same problem for all the material tags (mat-icon, mat-table, mat-label . . .).
In previous version (Angular 9), all was OK. Thanks for help.
Angular material update: It gives errors in some versions of angular material when running update scripts because of the update scripts do not run smoothly in some versions. What I did is updating material after getting everything done. So when I finish with all other updates, I just ran ng update @angular/material.
Getting started Add Angular Material to your project! Schematics Use schematics to quickly generate views with Material Design components. Theming Angular Material Customize your application with Angular Material's theming system. Theming your own components Use Angular Material's theming system in your own custom components.
In Angular 9 and 10 we can notice that the “ my-element is not a known element ” error is missing when our tests don’t have all required stubs. Make sure to check debug messages when running tests and add all absent stubs. Otherwise, you will have to update your test suite when the Angular team fixes this bug.
It seems that since version 9 Angular handles unknown elements in unit tests differently than the previous releases. If we forget to stub an element that we used inside a component under test, the test will pass. Furthermore, the message about an unknown element will be displayed only in the debug window.
Note 1 (fatal problem)
You are using lazy loading. somewhere in your project, you have the old syntax of lazy loading
{
...
loadChildren: 'path/to/your.module#YourModule'
}
Replace all of them in your project to:
{
...
loadChildren: () => import('path/to/your.module').then(m => m.YourModule)
}
Even if you think it is not related to your current feature. After doing this the problem will be solved.
Note2:
Also during the upgrade to Angular12 if some npm packages are broken you can use
npm i --save package-name --force
to install it for now.
Note3:
Also if you see some bugs in the ts files you can suppress(ignore) them by using // @ts-ignore
on top of the error line for now.
Note4
Also if you see an error like "Class is using Angular features but is not decorated. Please add an explicit Angular decorator".
add @Injectable()
on top of the class declaration.
Note5
In my idea, If You are upgrading from an older version of angular to angular 12. For doing this first create a project with
ng new APP_NAME --strict=false
which you don't have a strict mode for now.
When all problems are solved and you have a working project now you can create a new project which has strict mode.
:)-|-< If the answer was useful Vote +1 Please >-|-(:
i am assuming you are having lazy loaded modules.
if yes,
create a shared module,
import and export all material module in shared module,
import the shared module in root (app) module and feature (lazy loaded) modules.
if no, then what you have done was right, i guess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With