
Angular中文博客
分享让你更聪明
当项目中使用NzModalService的时候报错信息如下
ERROR ɵNotFound: R3InjectorError(DeferBlock Injector)[_NzModalService -> _NzModalService -> _NzModalService -> _NzModalService]:
NullInjectorError: No provider for _NzModalService!
组件中的代码如下
import {NzModalModule, NzModalService} from 'ng-zorro-antd/modal';
@Component({
selector: 'app-settings-base',
imports: [NzModalModule],
template: ``
})
export class SettingsBase {
public readonly modal: NzModalService = inject(NzModalService);
}
需要在app.config.ts中这样引入:
import {NzModalService} from 'ng-zorro-antd/modal';
export const appConfig: ApplicationConfig = {
providers: [
NzModalService // 新的代码
]
};
完成