大家好!
我是MEAN stack的新手,仍然在尝试进入它的基础。
我想做一个简单的认证。这是代码:
import { Component } from '@angular/core';
import { NavController, LoadingController } from 'ionic-angular';
import { Auth } from '../../providers/auth';
import { HomePage } from '../home/home';
@Component({
selector: 'signup-page',
templateUrl: 'signup-page.html'
})
export class SignupPage {
role: string;
email: string;
password: string;
constructor(public navCtrl: NavController, public authService: Auth, public loadingCtrl: LoadingController) {
}
register(){
this.showLoader();
let details = {
email: this.email,
password: this.password,
role: this.role
};
this.authService.createAccount(details).then((result) => {
this.loading.dismiss();
console.log(result);
this.navCtrl.setRoot(HomePage);
}, (err) => {
this.loading.dismiss();
});
}
showLoader(){
this.loading = this.loadingCtrl.create({
content: 'Authenticating...'
});
this.loading.present();
}
}
我得到的错误是:
[12:43:17] typescript: src/pages/signup-page/signup-page.ts, line: 31
Property 'loading' does not exist on type 'SignupPage'.
L30: this.authService.createAccount(details).then((result) => {
L31: this.loading.dismiss();
L32: console.log(result);
[12:43:17] typescript: src/pages/signup-page/signup-page.ts, line: 35
Property 'loading' does not exist on type 'SignupPage'.
L34: }, (err) => {
L35: this.loading.dismiss();
L36: });
[12:43:17] typescript: src/pages/signup-page/signup-page.ts, line: 42
Property 'loading' does not exist on type 'SignupPage'.
L42: this.loading = this.loadingCtrl.create({
L43: content: 'Authenticating...'
[12:43:17] typescript: src/pages/signup-page/signup-page.ts, line: 46
Property 'loading' does not exist on type 'SignupPage'.
L46: this.loading.present();
[12:43:17] transpile failed
任何人都可以澄清我我错过了什么,我应该学习什么与我的项目进行?
Try This…
export class SignupPage {
role: string;
email: string;
password: string;
loading: any;
constructor(public navCtrl: NavController, public authService: Auth, public loadingCtrl: LoadingController) {
}
....
}
问题在于您的showLoader()
方法。你在做:
this.loading = this.loadingCtrl.create({
content: 'Authenticating...'
});
this.loading.present();
在普通javascript中这可能是合法的代码,但是typescript会抱怨,因为你没有在你的类中定义loading
属性。只需像这样定义属性:
export class SignupPage {
role: string;
email: string;
password: string;
loading: LoadingController; //I'm assuming that's the correct type
constructor(public navCtrl: NavController, public authService: Auth, public loadingCtrl: LoadingController) {
}
....
}