首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >电容器v3状态栏:输入'SplashScreenPlugin‘不能分配给’提供者‘。

电容器v3状态栏:输入'SplashScreenPlugin‘不能分配给’提供者‘。
EN

Stack Overflow用户
提问于 2022-06-18 19:16:45
回答 1查看 165关注 0票数 -1

我正在运行带有电容器3的离子6+。我安装了电容状态栏和溅屏,如下所示:

代码语言:javascript
复制
npm install @capacitor/status-bar --save
npm install @capacitor/splash-screen --save

npx cap sync

然后像这样导入:

代码语言:javascript
复制
import { SplashScreen } from '@capacitor/splash-screen';
import { StatusBar, Style } from '@capacitor/status-bar';

其次是:

代码语言:javascript
复制
@NgModule({
  ..........
..........
 providers: [ StatusBar,
              SplashScreen,
             .......
             ]

vscode将StatusBar和SplashScreen标记为以下错误:

代码语言:javascript
复制
Type 'StatusBarPlugin' is not assignable to type 'Provider'.
Type 'SplashScreenPlugin' is not assignable to type 'Provider'.

我还尝试切换到使用@离子型本机/溅屏/ngx和@离子型本机/状态栏/ngx‘,尽管这清除了提供者的错误,但我收到常春藤的警告,这些插件需要更新。

有人能解释一下这个错误发生的原因吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-18 20:03:41

您不必将插件注册为提供程序。只需在服务/组件/等等中使用它们:

代码语言:javascript
复制
import { Component } from '@angular/core';
import { Badge } from '@robingenz/capacitor-badge';

@Component({
  selector: 'app-badge',
  templateUrl: './badge.page.html',
  styleUrls: ['./badge.page.scss'],
})
export class BadgePage {
  constructor() {}

  public async getBadgeCount(): Promise<number> {
    const result = await Badge.get();
    return result.count;
  }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72672091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档