类型 'FacebookOriginal' 不可分配给类型 'Provider'(Ionic 5 - Facebook ionic native)
Type 'FacebookOriginal' is not assignable to type 'Provider' (Ionic 5 - Facebook ionic native)
我在重新启动 ionic 应用程序后突然开始收到这些错误消息:
TS2322: Type 'FacebookOriginal' is not assignable to type 'Provider'. Type 'FacebookOriginal' is missing the following properties from type 'TypeProvider': apply, call, bind, prototype, and 5 more.
app.module
// More imports above
import {Facebook} from '@ionic-native/facebook/ngx'; <--- I triple checked that this is the correct import
@NgModule({
declarations: [
// List of components here
],
entryComponents: [],
imports: [
// List of modules here
],
providers: [
StatusBar,
SplashScreen,
IsLoggedInGuard,
FCM,
IsNotLoggedInGuard,
Facebook, // <----- Error here
{provide: RouteReuseStrategy, useClass: IonicRouteStrategy}
],
bootstrap: [AppComponent]
})
export class AppModule {
}
在我注入引用的地方:
'Facebook' refers to a value, but is being used as a type here. Did you mean 'typeof Facebook'?
login.component.ts
// More imports above
import {Facebook} from '@ionic-native/facebook/ngx';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'],
})
export class LoginComponent implements OnInit {
public datosBasicos: Basicos;
public colores: Color = new Color();
constructor(
public loginService: SessionService,
private router: Router,
private fb: Facebook, // <----- Error here
private platform: Platform,
private colorService: ColorService,
public basicosService: BasicosService
) {
}
async ngOnInit() {
// this.autologinIfPreview();
await this.loginService.loginAnonimo();
this.colores = this.colorService.color;
this.datosBasicos = await this.basicosService.findDatosBasicos().pipe(first()).toPromise();
}
public async loginFacebook() {
const fbResponse = await this.fb.login(['public_profile', 'user_friends', 'email']).then(); // Because of previous error, this isn't working at all
await this.loginService.loginFacebook(fbResponse);
this.router.navigate(['/main/home']).then();
// await this.loginService.loginFacebook();
}
如果我添加“typeof Facebook”,运行时会出现此错误:
This constructor is not compatible with Angular Dependency Injection because its dependency at index 2 of the parameter list is invalid.
This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator.
这个错误快把我逼疯了,我之前确实能够构建 ionic 应用程序并使用 Facebook 执行登录。我尝试重新安装插件和类型并更改它们的版本,但没有成功。
好的,我知道了!
在我的应用程序的其他地方,我使用了这个:
session.service.ts
import {FacebookLoginResponse} from '@ionic-native/facebook'; // <--- Here!!! should be: '@ionic-native/facebook/ngx'
public async loginFacebook(facebookResponse: FacebookLoginResponse): Promise<User> {
if (facebookResponse) {
const facebookCredential = firebase.auth.FacebookAuthProvider.credential(facebookResponse.authResponse.accessToken);
const userCredential = await firebase.auth().signInWithCredential(facebookCredential);
return userCredential.user;
}
return null;
}
希望这对某人有所帮助,这个错误浪费了时间
我在重新启动 ionic 应用程序后突然开始收到这些错误消息:
TS2322: Type 'FacebookOriginal' is not assignable to type 'Provider'. Type 'FacebookOriginal' is missing the following properties from type 'TypeProvider': apply, call, bind, prototype, and 5 more.
app.module
// More imports above
import {Facebook} from '@ionic-native/facebook/ngx'; <--- I triple checked that this is the correct import
@NgModule({
declarations: [
// List of components here
],
entryComponents: [],
imports: [
// List of modules here
],
providers: [
StatusBar,
SplashScreen,
IsLoggedInGuard,
FCM,
IsNotLoggedInGuard,
Facebook, // <----- Error here
{provide: RouteReuseStrategy, useClass: IonicRouteStrategy}
],
bootstrap: [AppComponent]
})
export class AppModule {
}
在我注入引用的地方:
'Facebook' refers to a value, but is being used as a type here. Did you mean 'typeof Facebook'?
login.component.ts
// More imports above
import {Facebook} from '@ionic-native/facebook/ngx';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'],
})
export class LoginComponent implements OnInit {
public datosBasicos: Basicos;
public colores: Color = new Color();
constructor(
public loginService: SessionService,
private router: Router,
private fb: Facebook, // <----- Error here
private platform: Platform,
private colorService: ColorService,
public basicosService: BasicosService
) {
}
async ngOnInit() {
// this.autologinIfPreview();
await this.loginService.loginAnonimo();
this.colores = this.colorService.color;
this.datosBasicos = await this.basicosService.findDatosBasicos().pipe(first()).toPromise();
}
public async loginFacebook() {
const fbResponse = await this.fb.login(['public_profile', 'user_friends', 'email']).then(); // Because of previous error, this isn't working at all
await this.loginService.loginFacebook(fbResponse);
this.router.navigate(['/main/home']).then();
// await this.loginService.loginFacebook();
}
如果我添加“typeof Facebook”,运行时会出现此错误:
This constructor is not compatible with Angular Dependency Injection because its dependency at index 2 of the parameter list is invalid. This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator.
这个错误快把我逼疯了,我之前确实能够构建 ionic 应用程序并使用 Facebook 执行登录。我尝试重新安装插件和类型并更改它们的版本,但没有成功。
好的,我知道了!
在我的应用程序的其他地方,我使用了这个:
session.service.ts
import {FacebookLoginResponse} from '@ionic-native/facebook'; // <--- Here!!! should be: '@ionic-native/facebook/ngx'
public async loginFacebook(facebookResponse: FacebookLoginResponse): Promise<User> {
if (facebookResponse) {
const facebookCredential = firebase.auth.FacebookAuthProvider.credential(facebookResponse.authResponse.accessToken);
const userCredential = await firebase.auth().signInWithCredential(facebookCredential);
return userCredential.user;
}
return null;
}
希望这对某人有所帮助,这个错误浪费了时间