我正在为浏览器和android构建混合应用程序,并且我使用Angular 7构建了我的整个项目。然后,我计划使用设备插件(Ionic Plugin {@ ionic-native-device}和{cordova-plugin-device}),我做对了所有事情,并与所有教程匹配,但是无论如何,该程序在每个平台上都始终返回null (例如浏览器,Android虚拟机和Android设备)
我已经从这里Ionic Plugin Device安装了所需的插件,并导入到组件和模块中
==========================组件================== =========
import { Component, OnInit, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';
import { Router, ActivatedRoute } from "@angular/router";
import { GlobalVarService } from './../services/global-var.service';
import { Device } from '@ionic-native/device/ngx'; <-- import
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent {
@ViewChild('f') loginForm: NgForm;
username : string;
password : string;
model:any = {
username:'',
password:''
}
constructor(private router: Router,
private gVar: GlobalVarService,
private route: ActivatedRoute,
private device: Device) {
console.log(this.device.uuid);
alert(this.device.uuid); <-- This is the way i call
}
onSubmit() {
this.gVar.processLogin(this.model.username, this.model.password, 'true');
}
onForgotPassword() {
this.router.navigate(['forgotpassword'], { relativeTo: this.route.parent });
}
onRegister() {
this.router.navigate(['register'], { relativeTo: this.route.parent });
}
}
===========================模块================== =========
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { Device } from '@ionic-native/device/ngx'; <--- also import
import { LoginComponent } from './login.component';
const routes: Routes = [
{
path: '',
component: LoginComponent
}
];
@NgModule({
imports: [
CommonModule,
FormsModule,
RouterModule.forChild(routes)
],
providers: [
Device <--- This is how i place
],
declarations: [LoginComponent]
})
export class LoginModule { }