我正在尝试按照以下说明在我的 Angular 应用程序中安装 ngx-color-picker:
https://www.npmjs.com/package/ngx-color-picker/v/16.0.0
使用以下命令安装它可以成功:
npm install ngx-color-picker --save
我可以运行
ng serve
并且没有出现错误。
但是当我像下面这样导入它时:
import { ColorPickerModule } from 'ngx-color-picker';
@NgModule({
...
imports: [
...
ColorPickerModule
]
})
执行时出现此错误
ng serve
:
Error: node_modules/ngx-color-picker/lib/color-picker.directive.d.ts:108:103 - error TS2344: Type '{ colorPicker: { alias: "colorPicker"; required: false; }; cpWidth: { alias: "cpWidth"; required: false; }; cpHeight: { alias: "cpHeight"; required: false; }; cpToggle: { alias: "cpToggle"; required: false; }; ... 33 more ...; cpExtraTemplate: { ...; }; }' does not satisfy the constraint '{ [key: string]: string; }'.
Property '"colorPicker"' is incompatible with index signature.
Type '{ alias: "colorPicker"; required: false; }' is not assignable to type 'string'.
我正在使用 Angular 15。
版本 15 和 16 似乎存在一些问题,可能是由于 Angular 或 TypeScript 的可组合性问题。我能够在 stackblitz 中复制该场景,并且版本 14 仍然工作得很好,请安装它并检查它是否有效,下面是相同的 stackblitz 供参考!
npm install ngx-color-picker@14 --save
package.json 片段
"dependencies": {
"@angular/animations": "^15.2.0",
"@angular/common": "^15.2.0",
"@angular/compiler": "^15.2.0",
"@angular/core": "^15.2.0",
"@angular/forms": "^15.2.0",
"@angular/platform-browser": "^15.2.0",
"@angular/platform-browser-dynamic": "^15.2.0",
"@angular/router": "^15.2.0",
"ngx-color-picker": "^14.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.12.0"
},