ionic-framework - 使用 Capacitor CallNumber 获取无效的提供程序错误
问题描述
我正在实施 CallNumber。如果我遵循ionic 文档,则没有提到在提供程序中包含 CallNumber,因此会引发错误:
错误:未捕获(承诺中):NullInjectorError:R3InjectorError(HomePageModule)[CallNumber -> CallNumber -> CallNumber -> CallNumber]:NullInjectorError:没有提供 CallNumber!
所以我在 app.module.ts 中添加 CallNumber 作为提供者
import { CallNumber } from '@ionic-native/call-number';
@NgModule({
declarations: [AppComponent, StudentModalPage],
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
BrowserTransferStateModule,
IonicStorageModule.forRoot(),
IonicModule.forRoot(),
FormsModule,
AppRoutingModule,
HttpClientModule,
ComponentsModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
],
providers: [
CallNumber,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
{
provide: APP_INITIALIZER,
useFactory: (platformId: object, response: any) => {
return () => {
// In the server.ts we added a custom response header with information about the device requesting the app
if (isPlatformServer(platformId)) {
if (response && response !== null) {
// Get custom header from the response sent from the server.ts
const mobileDeviceHeader = response.get('mobile-device');
// Set Ionic config mode?
}
}
};
},
deps: [PLATFORM_ID, [new Optional(), RESPONSE]],
multi: true
}
],
bootstrap: [AppComponent]
})
export class AppModule {
但现在我得到这个错误:
错误:NgModule 'AppModule' 的提供程序无效 - 只允许提供 Provider 和 Type 的实例,得到:[?[object Object]?, ..., ...]
我已经搜索了分配,找不到解决方案,也没有隐瞒错误,任何输入表示赞赏。
解决方案
我遇到了类似问题的解决方案,并从添加提供程序后创建的自动导入更改了我的导入:
{ CallNumber } from '@ionic-native/call-number';
至:
{ CallNumber } from '@ionic-native/call-number/ngx';
推荐阅读
- java - 运行此活动后应用程序没有响应
- c# - WPF 绑定只工作一次
- jquery - jQuery 劫持 TypeScript 的“this”引用
- ansible - How can Ansible skip ./configure and make install when already run
- vba - 在不同工作表中更改触发宏
- r - Shiny SelectInput and SelectizeInput
- c# - How to Avoid "A task was cancelled" when debugging
- android - Smsgateway.me API - 在 V4 上禁用 REST Mod
- vb6 - 在 VB6 中,如何访问 FileSystem.GetFileInfo()?
- ruby-on-rails - gitlab-ci 找不到 config/database.yml,尽管它不应该存在于我的仓库中