gpt4 book ai didi

Angular: how to modify a method of library(Angular:如何修改库的方法)

转载 作者:bug小助手 更新时间:2023-10-22 17:34:56 28 4
gpt4 key购买 nike



I am using ng-select library (v9.x) (https://www.npmjs.com/package/@ng-select/ng-select)
And now this library has an issue on all versions (https://github.com/ng-select/ng-select/pull/2134), but only have PR to fix this issue on the latest version (>10.x).

我正在使用ng选择库(v9.x)(https://www.npmjs.com/package/@ng select/ng select)现在这个库在所有版本上都有问题(https://github.com/ng-select/ng-select/pull/2134),但只有PR才能在最新版本(>10.x)上解决此问题。


I want to extend the NgSelectComponent to override a method of this component (focus method) to fix that issue.

我想扩展NgSelectComponent来覆盖这个组件的一个方法(焦点方法)来解决这个问题。


So, how can I do that?

那么,我该怎么做呢?


更多回答
优秀答案推荐

you can fork the library form GitHub, do your fixes and then package the library, create a tar.gz and install it locally.

您可以从GitHub派生库,进行修复,然后打包库,创建tar.gz并在本地安装。


更多回答

Do you mean clone code, fix it, and use it the same as a component.

你的意思是克隆代码,修复它,并将其作为组件使用吗。

yes, when you clone the code and edit it, you essentially created a fork

是的,当您克隆并编辑代码时,您实际上创建了一个fork

Thank you @Zerotwelve. Actually, I don't understand after editing the code in the fork branch and commit it. How can I use it in my project same as installing the new version "@ng-select/ng-select": "^9.x.x.fixversion", I will try to investigate more. If you have more details about the way to do that, please let me know.

谢谢你@零点十二。事实上,在编辑了fork分支中的代码并提交后,我不明白。我如何在我的项目中使用它,就像安装新版本“@ng select/ng select”:“^9.x.x.fixversion”一样,我会尝试进行更多的研究。如果你有更多关于方法的细节,请告诉我。

Build the libary using the ng build command and then move the the build (or dist) directory and pack it with the npm pack command. This should create a tar.gz that you can use for installation i.e. npm install /path/to/my-lib.tar.gz

使用ng-Build命令构建库,然后移动Build(或dist)目录并使用npm-pack命令对其进行打包。这应该创建一个可以用于安装的tar.gz,即npm install/path/to/my-lib.tar.gz

thanks for your support, I tried an other way to fix this issue by use @ViewChild(NgSelectComponent) ngSelectComponent: NgSelectComponent; and override method in ng-select component this.ngSelectComponent['focus'] = () => {}

感谢您的支持,我尝试了另一种方法来解决这个问题,使用@ViewChild(NgSelectComponent)NgSelectComponent:NgSelectComponent;和覆盖ngselect component this.ngSelectComponent['cus']=()=>{}中的方法

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com