简体   繁体   English

Angular 14 组件不识别进口模块

[英]Angular 14 Components Aren't Recognizing Imported Modules

I have a module in my Angular 14.x project that is structured as such.我的 Angular 14.x 项目中有一个模块,其结构是这样的。

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { MatProgressSpinner, MatSpinner, MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatStep, MatStepper, MatStepperModule } from '@angular/material/stepper';
import { MatDialogModule } from '@angular/material/dialog'
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatNativeDateModule } from '@angular/material/core';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { ModalComponent } from './modal/modal.component';
import { IconsComponent } from './icons/icons.component';
import { AlertComponent } from './alert/alert.component';
import { PaginatorComponent } from './paginator/paginator.component';
import { LoaderComponent } from './loader/loader.component';
import { GroupSlideComponent } from './group-slide/group-slide.component';
import { VjsPlayerComponent } from './vjs-player/vjs-player.component';
import { FilterPipe } from '@src/app/core/pipes/filter.pipe';
import { ContentTagPipe } from '@src/app/core/pipes/content-tag.pipe';
import { AccessDialogComponent } from './access-dialog/access-dialog.component';
import { BtnSlidenavComponent } from './btns/btn-slidenav/btn-slidenav.component';
import { ArrowLinkComponent } from './btns/arrow-link/arrow-link.component';
import { ContentSlideComponent } from './content-slide/content-slide.component';
import { FilterComponent } from './filter/filter.component';
import { MatExpansionModule } from '@angular/material/expansion';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MobileFilterComponent } from './filter/mobile-filter/mobile-filter.component';
import { BtnBackComponent } from './btns/btn-back/btn-back.component';

@NgModule({
  declarations: [
    ModalComponent,
    IconsComponent,
    AlertComponent,
    PaginatorComponent,
    LoaderComponent,
    GroupSlideComponent,
    VjsPlayerComponent,
    FilterPipe,
    ContentTagPipe,
    AccessDialogComponent,
    BtnSlidenavComponent,
    ArrowLinkComponent,
    ContentSlideComponent,
    FilterComponent,
    MobileFilterComponent,
    BtnBackComponent
  ],
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    MatStepperModule,
    MatFormFieldModule,
    MatNativeDateModule,
    MatDatepickerModule,
    MatProgressSpinnerModule,
    MatDialogModule,
    RouterModule,
    MatExpansionModule,
    RouterModule
  ],
  exports: [
    ModalComponent,
    IconsComponent,
    MatProgressSpinner,
    MatSpinner,
    MatStepper,
    MatStep,
    AlertComponent,
    GroupSlideComponent,
    PaginatorComponent,
    LoaderComponent,
    VjsPlayerComponent,
    FilterPipe,
    ContentTagPipe,
    BtnSlidenavComponent,
    BtnBackComponent,
    ArrowLinkComponent,
    ContentSlideComponent,
    FilterComponent,
    MobileFilterComponent
  ]
})
export class UIModule {
}

After upgrading to Angular 14.x I get hundreds of compile errors stating "Can't bind to... " stated directive.升级到 Angular 14.x 后,我收到数百个编译错误,说明"Can't bind to... "指令。

The individual component folders are structured as such.各个组件文件夹的结构是这样的。

component-name
 - component-name.component.html
 - component-name.component.scss
 - component-name.component.ts
 - component-name.component.spec.ts

在此处输入图像描述

We upgraded from Angular 12 -> Angular 13 -> Angular 14. Everything was working prior to upgrading to Angular 14.我们从 Angular 12 -> Angular 13 -> Angular 14 升级。在升级到 ZC31C335EF37283C451C335EF37283C71C335EF372831331C335EF37283C451B18BA0DD317DE1Z 14 之前,一切正常。

This is our tsconfig.json file.这是我们的 tsconfig.json 文件。

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitAny": false,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2020",
    "module": "es2020",
    "allowSyntheticDefaultImports": true,
    "lib": [
      "es2018",
      "dom"
    ],
    "strictPropertyInitialization": false,
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true,
    "strictPropertyInitialization": false,
    "types": [
      "node"
    ]
  }
}

Any suggestions on how to resolve the import errors like such would be very much appreciated.非常感谢有关如何解决此类导入错误的任何建议。

Error: src/app/components/ui/icons/icons.component.html:318:43 - error NG8002: Can't bind to 'ngStyle' since it isn't a known property of ':svg:svg'.

318   <svg xmlns="http://www.w3.org/2000/svg" [ngStyle]="{ 'width': width, 'height': height, 'margin': margin }" viewBox="0 0 20 20" fill="currentColor">

Did you make any other modifications apart from upgrading?除了升级之外,您是否进行了其他修改?

This kind of error is usually caused by:这种错误通常是由以下原因引起的:

  1. not importing CommonModule where it's needed, or不在需要的地方导入CommonModule ,或者
  2. your local server getting stuck, in which case try a restart.您的本地服务器卡住了,在这种情况下尝试重新启动。

I needed to restart VSCode.我需要重新启动 VSCode。 After restarting the import errors were correctly identified and I was able to resolve them.重新启动后,导入错误被正确识别,我能够解决它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM