我是IONIC框架的新手。需要使用IONIC 3和firebase开发移动应用程序,用于存储数据和进行身份验证。通过npm安装所有必需的模块。
按照以下步骤创建IONIC 3应用程序 1)离子启动TestDemo选项卡 2)离子生成页面注册 3)npm install firebase angularfire2 --save 4)导入到app.module.ts
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { AngularFireModule } from 'angularfire2';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
WelcomePage,
LoginPage,
SignupPage,
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(environment.firebase),
AngularFireAuthModule
]
5)signup.ts
import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
@IonicPage()
@Component({
selector: 'page-signup',
templateUrl: 'signup.html',
})
export class SignupPage {
@ViewChild("email") email;
@ViewChild("mobileno") mobileno;
@ViewChild("username") username;
@ViewChild("password") password;
constructor(public navCtrl: NavController, public navParams: NavParams,private fire: AngularFireAuth ) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad SignupPage');
}
async signup(){
try{
const result = await this.fire.auth.createUserWithEmailAndPassword(this.username.value,this.password.value);
console.log(result);
}
catch(err){
console.log("Error");
}
}
}
6)signup.html
<ion-header>
<ion-navbar>
<ion-title>signup</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item>
<ion-label floating>Email</ion-label>
<ion-input type="text" #email></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Mobile No</ion-label>
<ion-input type="text" #mobileno></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Username</ion-label>
<ion-input type="text" #username></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Password</ion-label>
<ion-input type="password" #password></ion-input>
</ion-item>
<button ion-button round (click)="signup()">Sign Up</button>
</ion-list>
</ion-content>
7)离子发球
然后它给出以下错误
Error: Cannot find module "@firebase/auth"
at webpackMissingModule (http://localhost:8100/build/vendor.js:66020:65)
at Object.__webpack_exports__.c (http://localhost:8100/build/vendor.js:66020:156)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:65949:72)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:112662:64)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:65937:70)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.101 (http://localhost:8100/build/main.js:76:76)
请帮助解决这个问题。 提前致谢