ANGULAR 6:错误 TS2315:类型“ModuleWithProviders”不是通用的

2023-11-25

您好,我遇到了一个与任何事情都无法关联的问题。

我展示了一些我的代码,希望它能有用。

考虑一下当我开始创建反应式表单时这个问题就出现了。

首先,这是我的 package.json:

{
  "name": "name",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.1.2",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@ng-bootstrap/ng-bootstrap": "^2.2.0",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-angular": "~0.6.8",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

这是我的应用程序模块:

import {BrowserModule} from '@angular/platform-browser';
import {ModuleWithProviders, NgModule} from '@angular/core';
import {AppComponent} from './app.component';
import {SideBarComponent} from './components/side-bar/side-bar.component';
import {HttpRequestProcessComponent} from './components/http-request-process/http-request-process.component';
import {ProcessFormComponent} from './components/form/process-form/process-form.component';
import {HttpResponseComponent} from './components/http-response/http-response.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {HttpClientModule} from '@angular/common/http';
import {RouterModule, Routes} from '@angular/router';
import {RuleFormComponent} from './components/form/rule-form/rule-form.component';
import {ProcessComponent} from './components/process/process.component';
import {TestCasesComponent} from './components/test-cases/test-cases.component';
import {FilterPipe, SortByPipe} from './pipes/filter.pipe';
import {SalableProductFormComponent} from './components/form/salable-product-form/salable-product-form.component';
import {CheckOrderFormComponent} from './components/form/check-order-form/check-order-form.component';
import {ModalComponent} from './components/modal/modal.component';
import {HttpProcessiComponent} from "./components/http-textarea/http-processi/http-processi.component";
import {HttpRegoleComponent} from "./components/http-textarea/http-regole/http-regole.component";
import {HttpProdottiVendibiliComponent} from "./components/http-textarea/http-prodotti-vendibili/http-prodotti-vendibili.component";

const appRoutes: Routes = [
  {
    path: '',
    redirectTo: 'processi',
    pathMatch: 'full'
  },
  {
    path: 'processi',
    component: ProcessComponent,
    children: [
      {
        path: '',
        component: ProcessFormComponent,
        outlet: 'form'
      }
    ]
  },
  {
    path: 'regole',
    component: ProcessComponent,
    children: [
      {
        path: '',
        component: RuleFormComponent,
        outlet: 'form'
      }
    ]
  },
  {
    path: 'verifica-ordini',
    component: ProcessComponent,
    children: [
      {
        path: '',
        component: CheckOrderFormComponent,
        outlet: 'form'
      }
    ]
  },
  {
    path: 'prodotti-vendibili',
    component: ProcessComponent,
    children: [
      {
        path: '',
        component: SalableProductFormComponent,
        outlet: 'form'
      }
    ]
  }
];

const alternativeRoute = [
  {
    path: '',
    redirectTo: 'processi',
    pathMatch: 'full'
  },
  {
    path: 'processi',
    component: ProcessFormComponent
  },
  {
    path: 'regole',
    component: RuleFormComponent
  },
  {
    path: 'verifica-ordini',
    component: CheckOrderFormComponent,
  },
  {
    path: 'prodotti-vendibili',
    component: SalableProductFormComponent,
  }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);


@NgModule({
  declarations: [
    AppComponent,
    SideBarComponent,
    HttpRequestProcessComponent,
    ProcessFormComponent,
    HttpResponseComponent,
    RuleFormComponent,
    ProcessComponent,
    TestCasesComponent,
    FilterPipe,
    SortByPipe,
    SalableProductFormComponent,
    CheckOrderFormComponent,
    // ProductFormElementComponent,
    ModalComponent,
    HttpProcessiComponent,
    HttpRegoleComponent,
    HttpProdottiVendibiliComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    RouterModule.forRoot(appRoutes,
      {enableTracing: false}),
    FormsModule,
    ReactiveFormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule {
}

确切的错误是:

node_modules/@angular/forms/src/form_providers.d.ts(22,9) 中的错误:错误 TS2315:类型“ModuleWithProviders”不是通用的。

它似乎与我的代码没有直接关系,而是与 Angular 更深层次的配置级别相关。

在我的任何组件中显示任何错误。

请指教。

EDIT我这样修改了路由配置:

const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, enableTracing: false});

我添加了路由imports。问题仍然存在。


表单模块版本与核心不匹配,

"dependencies": {
  ...
  "@angular/core": "^6.0.3",
  "@angular/forms": "^6.1.2",

要更正它,请重新安装表单yarn add @angular/[email protected] or npm install @angular/[email protected](无论您使用哪个安装程序开始)。
安装程序应该会告诉您,之后可能还有其他依赖项需要调整。

如果您比较 6.0.3 和 6.1.2 源form_providers.ts在 github 上,这是导致错误的更改:

6.0.3

import {ModuleWithProviders, NgModule} from '@angular/core';
...
export class ReactiveFormsModule {
  static withConfig(opts: {
    /** @deprecated as of v6 */ warnOnNgModelWithFormControl: 'never' | 'once' | 'always'
  }): ModuleWithProviders {

6.1.2

import {ModuleWithProviders, NgModule} from '@angular/core';
...
export class ReactiveFormsModule {
  static withConfig(opts: {
    /** @deprecated as of v6 */ warnOnNgModelWithFormControl: 'never' | 'once' | 'always'
  }): ModuleWithProviders<ReactiveFormsModule> {
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ANGULAR 6:错误 TS2315:类型“ModuleWithProviders”不是通用的 的相关文章

随机推荐

  • 方形拼图解决方案

    Question given an integer number n print the numbers from 1 up to n2 like this n 4 结果是 01 02 03 04 12 13 14 05 11 16 15
  • 函数调用中的 C++ 临时对象生命周期

    当我们通过原始指针或引用将临时智能指针管理的对象传递给函数时 标准是否保证该对象的生存期将延长到函数的生存期 include
  • JQuery JEditable - 如何禁用点击编辑

    我想知道您是否可以停止点击时编辑文本 我有一个单独的编辑按钮来使文本可编辑 这是我希望用户能够编辑文本的唯一方法 因此想要关闭单击编辑吗 有任何想法吗 布里特是对的 添加一个自定义事件 然后用按钮触发它 这是一些代码来解释它 自定义事件 i
  • 使用 N-API 将数据流式传输到 Node.js C++ 插件

    我正在为 NodeJS 构建一个 C 插件 我想将数据从 C 异步流式传输到 Node 我找到了这篇文章 https nodeaddons com streaming data into a node js c addon 然而 我想使用
  • Django:HttpResponseRedirect 不起作用

    我是 Python Django 和整体编程的新手 我需要有关 HttpResponseRedirect 的帮助 因为它在我的登录视图中不起作用 它确实可以在我的主视图文件中工作 但不是我想要的方式 我没有重定向到所需的页面 而是只在同一页
  • 如何在API平台上保存与实体的嵌套关系

    我有两个实体 Question and 选择其中 Question 与 Alternative 有 OneToMany 关系 我正在尝试发送带有嵌套文档的 JSON选择通过 POST 到QuestionAPI 平台 API 平台返回以下错误
  • 如何在 Dart 中逐行读取文件

    这个问题是一个问题的延续上一个问题 我编写了以下代码来确定是否File openRead 创建了一个可以逐行流式传输的 Stream 事实证明答案是否定的 读取整个文件 然后传递到下一个转换 我的问题是 如何在 Dart 中逐行流式传输文件
  • 如何在不复制数据的情况下连接 pandas DataFrame?

    我想连接两个 pandas DataFrame 而不复制数据 也就是说 我希望连接的 DataFrame 成为两个原始 DataFrame 中数据的视图 我尝试使用 concat 但不起作用 此代码块显示更改基础数据会影响连接的两个 Dat
  • 从 SQLite3 导出数据

    我需要一种简单的方法从包含多个表的 SQLite 数据库中导出数据 然后将它们导入到另一个数据库中 这是我的场景 我有 5 个表 A B C D E 每个表都有一个主键作为第一列 称为 ID 我想要一个 Unix 命令 它仅以可以导入到另一
  • 如何反序列化 Kubernetes YAML 文件

    如何将 Kubernetes YAML 文件反序列化为 Go 结构 我查看了kubectl代码 但不知何故 每个 YAML 文件都会出现错误 no kind Deployment is registered for version apps
  • Terraform EKS 标记

    我遇到了 Terraform EKS 标记问题 并且似乎没有找到可行的解决方案来在创建新集群时标记所有 VPC 子网 提供一些背景信息 我们有一个 AWS VPC 在其中将多个 EKS 集群部署到子网中 我们不会在 EKS 集群创建过程中创
  • FirebaseError:[code=resource-exhausted]:资源已耗尽(例如检查配额)

    我有一个大小为 10000 的数组 所有这些都是文档 ID 我正在运行一个数组 需要从 Firestore 获取文档数据 并且需要在每个文档中添加新字段 但我面临以下错误 例如 firebase firestore Firestore 5
  • DATETIME 值在 SQLite 中如何工作?

    我正在创建 Android 应用程序 需要保存创建记录的日期 时间 然而 SQLite 文档说 SQLite 没有为存储日期和 或时间而预留的存储类 并且它 能够将日期和时间存储为 TEXT REAL 或 INTEGER 值 使用一种类型而
  • PHP 中有比任何数字都大的东西吗?

    我需要在 PHP 中模拟 So that min number 总是 number 我想 对于整数 你可以使用PHP INT MAX 以下代码 var dump PHP INT MAX 在我的机器上给出以下输出 int 2147483647
  • AccessType.FIELD、AccessType.PROPERTY 和 @Access 的用途是什么

    我只是想知道所有这些注释之间有什么区别 为什么我们使用这些 意味着它们没有影响 尤其是字段级别和属性级别 使用混合级别注释的目的是什么 Entity Access AccessType FIELD class Employee why th
  • C 中是否有单消费者单生产者无锁队列实现?

    我正在编写一个带有消费者线程和生产者线程的程序 现在看来队列同步在程序中是一个很大的开销 我寻找了一些无锁队列实现 但只找到了Lamport的版本和PPoPP上的改进版本 08 enqueue nonblock data if NULL b
  • 按子数组的数量对数组进行排序

    我有一个看起来像这样的数组 Array some first category gt Array some first name gt Array 0 gt email protected 1 gt email protected 2 gt
  • javax.net.ssl.SSLException:证书中的主机名与android不匹配

    我正在创建一个 Android 应用程序 其中我将数据发送到 Web 服务 但我收到 javax net ssl SSLException 证书中的主机名与 android 不匹配的错误 这是我的代码 AsyncHttpClient cli
  • IFrame (HTML) 是否已过时? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心以获得指导 收到的信息相互矛盾 希望不
  • ANGULAR 6:错误 TS2315:类型“ModuleWithProviders”不是通用的

    您好 我遇到了一个与任何事情都无法关联的问题 我展示了一些我的代码 希望它能有用 考虑一下当我开始创建反应式表单时这个问题就出现了 首先 这是我的 package json name name version 0 0 0 scripts n