gpt4 book ai didi

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

转载 作者:bug小助手 更新时间:2023-10-24 19:06:43 25 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-SELECT库(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以覆盖此组件的方法(Focus方法)以修复该问题。


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

是的,当您克隆代码并对其进行编辑时,您实际上创建了一个分支

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.

感谢你@Zero12。实际上,我不明白在fork分支中编辑代码并提交它之后。如何在我的项目中使用它与安装新版本“@ng-select/ng-select”:“^9.x.x.fix Version”一样,我将尝试调查更多。如果您有更多关于如何做到这一点的细节,请让我知道。

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命令构建库,然后移动构建(或dist)目录,并使用npm pack命令将其打包。这应该会创建一个可用于安装的tar.gz,即NPM安装/路径/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;和覆盖ng-select组件this.ngSelectComponent[‘Focus’]=()=>{}的其他方法来解决此问题

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