我正在使用電容器 3 運行離子 6 。我安裝了電容器狀態欄和閃屏,如下所示:
npm install @capacitor/status-bar --save
npm install @capacitor/splash-screen --save
npx cap sync
然后像這樣匯入:
import { SplashScreen } from '@capacitor/splash-screen';
import { StatusBar, Style } from '@capacitor/status-bar';
其次是:
@NgModule({
..........
..........
providers: [ StatusBar,
SplashScreen,
.......
]
vscode 將 StatusBar 和 SplashScreen 標記為以下錯誤:
Type 'StatusBarPlugin' is not assignable to type 'Provider'.
Type 'SplashScreenPlugin' is not assignable to type 'Provider'.
我還嘗試切換回使用 @ionic-native/splash-screen/ngx' 和 @ionic-native/status-bar/ngx' ,即使這清除了提供程式錯誤,我也收到了來自 ivy 的警告,這些插件需要更新。
誰能解釋為什么會發生這個錯誤?
uj5u.com熱心網友回復:
您不必將插件注冊為提供者。只需在您的服務/組件/等中使用它們:
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;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/495183.html
