Angular13升级后的Mixins/Webpack问题
创始人
2024-10-22 00:01:42
0
  1. 将 Mixin 的实现替换为继承

在 ng-packagr 的 v13 中,mixin 的实现方式发生了变化,因此你可能需要修改你的代码。在混入(mixin)中,一些 @Input()@Output() 被转换为 Angular settergetter。在 Angular v13 中,如果某个组件继承了混合类型,还需要在该组件中手动实现与指令的绑定。因此,为了避免这些问题,建议在升级到 Angular 13 时,将mixin的实现方式替换为继承。

以下是一个示例代码,展示如何使用类继承来代替 mixins。

import { Component, Input } from '@angular/core';
import { SimpleMixin } from './mixin';

class BaseComponent extends SimpleMixin {
  @Input() defaultValue: string = '';
}

@Component({
  selector: 'app-component',
  template: `

{{ hello() }}

`, }) export class AppComponent extends BaseComponent { hello() { return `Hello ${this.name || this.defaultValue}!`; } }
  1. 在 webpack 配置中添加引用 tsconfig.json 的选项。

如果你遇到了升级到 Angular 13 后构建过程中,遇到了类似于下面这种的 TypeScript 编译错误:

ERROR in ./src/app/app.module.ts 25:100-110
TS2769: No overload matches this call.
  Overload 1 of 3, '(options: CompilerOptions | undefined, fileNames?: readonly string[] | undefined): Program', gave the following error.
    Argument of type 'Configuration' is not assignable to parameter of type 'CompilerOptions'.
  Overload 2 of 3, '(jsonObject: any, basePath: string, existingOptions?: CompilerOptions | undefined, configFilePath?: string | undefined, watchOptions?: WatchOptions | undefined): P...', gave the following error.
    Argument of type 'Configuration' is not assignable to parameter of type 'TsConfigSourceFile | CompilerOptions'.

那么这可能是由于 TypeScript 引用了不同的tsconfig.json造成的。解决办法是在 webpack 配置中添加引用 tsconfig.json 的选项。

angular.json 文件中的 build 配置中添加以下内容:

相关内容

热门资讯

安装apache-beam==... 出现此错误可能是因为用户的Python版本太低,而apache-beam==2.34.0需要更高的P...
避免在粘贴双引号时向VS 20... 在粘贴双引号时向VS 2022添加反斜杠的问题通常是由于编辑器的自动转义功能引起的。为了避免这个问题...
Android Recycle... 要在Android RecyclerView中实现滑动卡片效果,可以按照以下步骤进行操作:首先,在项...
omi系统和安卓系统哪个好,揭... OMI系统和安卓系统哪个好?这个问题就像是在问“苹果和橘子哪个更甜”,每个人都有自己的答案。今天,我...
原生ios和安卓系统,原生对比... 亲爱的读者们,你是否曾好奇过,为什么你的iPhone和安卓手机在操作体验上有着天壤之别?今天,就让我...
Android - 无法确定任... 这个错误通常发生在Android项目中,表示编译Debug版本的Java代码时出现了依赖关系问题。下...
Android - NDK 预... 在Android NDK的构建过程中,LOCAL_SRC_FILES只能包含一个项目。如果需要在ND...
Akka生成Actor问题 在Akka框架中,可以使用ActorSystem对象生成Actor。但是,当我们在Actor类中尝试...
Agora-RTC-React... 出现这个错误原因是因为在 React 组件中使用,import AgoraRTC from “ago...
Alertmanager在pr... 首先,在Prometheus配置文件中,确保Alertmanager URL已正确配置。例如:ale...