Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在ModalHelper中使用st组件,会出现 NullInjectorError: No provider for _NzContextMenuService,导致弹出框页面无法加载 #2479

Open
skmbw opened this issue Feb 5, 2024 · 10 comments

Comments

@skmbw
Copy link

skmbw commented Feb 5, 2024

Reproduction link

http://github.com/skmbw/ng-alain-17.2.0

Steps to reproduce

在ModalHelper中使用st组件,会出现 NullInjectorError: No provider for _NzContextMenuService,导致弹出框页面无法加载

What is expected?

正常打开弹出框

What is actually happening?

打不开弹出框

Environment Info
ng-alain 17.2.0
Browser chrome 121
Copy link

alain-bot bot commented Feb 5, 2024

Translation of this issue:

Use ST components in Modalhelper, and NULLLINJECTORRORRRRORRRRORORRRRORRORROROVIDER FOR

REPRODUCTION LINK

[http://github.com/skmbw/ng-alain-17.2.0.

STEPS To Reproduce

Use ST components in Modalhelper, and NULLLINJECTORRORRRRORRRRORORRRRORRORROROVIDER FOR

What is exfected?

Open the pop -up box normally

What is actually happy?

Can't open the pop -up box

| ENVIRONMENT | Info |
| --- | --- | |
| NG-ALAIN | 17.2.0 |
| Browser | Chrome 121 |

@skmbw
Copy link
Author

skmbw commented Feb 5, 2024

错误出现在文件st.component.mjs的113行,this.cms = inject(NzContextMenuService);

@skmbw
Copy link
Author

skmbw commented Feb 17, 2024

就像这样,ModalHelper.createStatic(DataRuleGroupEditComponent......,创建模态框,如果DataRuleGroupEditComponent(模态框要弹出的组件,包含st组件),模态框将无法渲染

@LingerInside
Copy link

LingerInside commented Mar 5, 2024

就像这样,ModalHelper.createStatic(DataRuleGroupEditComponent......,创建模态框,如果DataRuleGroupEditComponent(模态框要弹出的组件,包含st组件),模态框将无法渲染

使用standalone component,NgModule中imports当前component

@Component({
  standalone: true,
  imports: [STModule]
})

@cipchk
Copy link
Member

cipchk commented Mar 7, 2024

@skmbw 我也不无重现出你所说的情况 ,png:

image

@skmbw
Copy link
Author

skmbw commented Mar 9, 2024

就像这样,ModalHelper.createStatic(DataRuleGroupEditComponent......,创建模态框,如果DataRuleGroupEditComponent(模态框要弹出的组件,包含st组件),模态框将无法渲染

使用standalone component,NgModule中imports当前component

@Component({
  standalone: true,
  imports: [STModule]
})

你这个方法是对的。组件要在modal中弹出,如果是NgModule组件,且组件中使用了st组件,是会报缺少注入器,无法使用inject方法注入NzContextMenuService,如果不包含st组件,是没问题的;如果组件是standalone组件,包含或者不包含st组件,都是不会报错的。因为我原来很多组件都是NgModule组件,不是standalone组件,一个一个改为standalone,太费时。我的解决方法是,将NzContextMenuService改为使用构造函数注入,不使用inject方法注入,这样就没有问题了。

@skmbw
Copy link
Author

skmbw commented Mar 9, 2024

@skmbw 我也不无重现出你所说的情况 ,png:

image

组件要在modal中弹出,如果是NgModule组件,且组件中使用了st组件,是会报缺少注入器,无法使用inject方法注入NzContextMenuService,如果不包含st组件,是没问题的;如果组件是standalone组件,包含或者不包含st组件,都是不会报错的。因为我原来很多组件都是NgModule组件,不是standalone组件,一个一个改为standalone,太费时。我的解决方法是,将st.component中的NzContextMenuService改为使用构造函数注入,不使用inject方法注入,这样就没有问题了。那么引申出来一个问题,为什么NzContextMenuService可以使用构造函数注入,不能使用inject方法注入,我就没有深入研究了。

@rxxy
Copy link

rxxy commented May 3, 2024

同遇到了,现在改为standalone好了

@lywzx
Copy link

lywzx commented May 16, 2024

就像这样,ModalHelper.createStatic(DataRuleGroupEditComponent......,创建模态框,如果DataRuleGroupEditComponent(模态框要弹出的组件,包含st组件),模态框将无法渲染

使用standalone component,NgModule中imports当前component

@Component({
  standalone: true,
  imports: [STModule]
})

你这个方法是对的。组件要在modal中弹出,如果是NgModule组件,且组件中使用了st组件,是会报缺少注入器,无法使用inject方法注入NzContextMenuService,如果不包含st组件,是没问题的;如果组件是standalone组件,包含或者不包含st组件,都是不会报错的。因为我原来很多组件都是NgModule组件,不是standalone组件,一个一个改为standalone,太费时。我的解决方法是,将NzContextMenuService改为使用构造函数注入,不使用inject方法注入,这样就没有问题了。

具体是咋改?更改node_modules中的代码?

@PayHard
Copy link

PayHard commented Jun 2, 2024

我是使用DrawerHelper创建时出现这个错误,抽屉中有表格就报错不能弹出,没有表格就可以弹出
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants