gpt4 book ai didi

javascript - ionic native /日期选择器 StaticInjectorError

转载 作者:行者123 更新时间:2023-12-04 16:28:38 27 4
gpt4 key购买 nike

所以我正在尝试使用 DatePicker ,但是我得到了一个 StaticInjectorError

这是我尝试过的:

import {Component} from '@angular/core';
import {TextService} from '@core/services/text/text.service';
import {Router} from '@angular/router';
import {FeaturePage} from '@feature/paths';
import {User} from '@core/classes/user';
import {DatePicker} from '@ionic-native/date-picker/ngx';

@Component({
selector: 'app-setup',
templateUrl: 'setup.page.html',
styleUrls: ['setup.page.scss'],
})
export class SetupPage {

user: User;

constructor(private textService: TextService, private router: Router, private datePicker: DatePicker) {
this.user = new User();

this.datePicker.show({
date: new Date(),
mode: 'date',
androidTheme: this.datePicker.ANDROID_THEMES.THEME_HOLO_DARK
}).then(
date => console.log('Got date: ', date),
err => console.log('Error occurred while getting date: ', err)
);
}

}

我收到以下错误:

core.js:15724 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[SetupPage -> DatePicker]: 
StaticInjectorError(Platform: core)[SetupPage -> DatePicker]:
NullInjectorError: No provider for DatePicker!
Error: StaticInjectorError(AppModule)[SetupPage -> DatePicker]:
StaticInjectorError(Platform: core)[SetupPage -> DatePicker]:
NullInjectorError: No provider for DatePicker!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:8896)
at resolveToken (core.js:9141)
at tryResolveToken (core.js:9085)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:8982)
at resolveToken (core.js:9141)
at tryResolveToken (core.js:9085)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:8982)
at resolveNgModuleDep (core.js:21218)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:21907)
at resolveNgModuleDep (core.js:21218)
at resolvePromise (zone.js:831)
at resolvePromise (zone.js:788)
at zone.js:892
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:17290)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)

如果您没有导入模块,通常会发生这种情况,但是在文档中没有要导入的模块?

最佳答案

尝试在 app.module.ts 中添加这个:

import { DatePicker } from '@ionic-native/date-picker/ngx';

[...]

@NgModule({
...
providers: [
...,
DatePicker
]
...
})

通常所有 @ionic-native 包都必须导入到 app.module.ts 的 providers 数组中,即使 ionic 文档中没有提及。

关于javascript - ionic native /日期选择器 StaticInjectorError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57147726/

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