gpt4 book ai didi

angular - ionic 找不到模块 '../providers/auth-service/auth-service'

转载 作者:太空狗 更新时间:2023-10-29 17:42:55 24 4
gpt4 key购买 nike

我正在尝试在 ionic angular 3.3.0 中创建登录/注册。我收到错误找不到模块'../providers/auth-service/auth-service'。在 login.ts 文件中。请帮忙!

auth-service.ts

       import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';

/*
Generated class for the AuthServiceProvider provider.

See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
export class User {
name: string;
email: string;

constructor(name: string, email: string) {
this.name = name;
this.email = email;
}
}
@Injectable()
export class AuthServiceProvider {
currentUser: User;
public login(credentials) {
if (credentials.email === null || credentials.password === null) {
return Observable.throw("Please insert credentials");
} else {
return Observable.create(observer => {
// At this point make a request to your backend to make a real check!
let access = (credentials.password === "pass" && credentials.email === "email");
this.currentUser = new User('ian', 'ianlikono@gmail.com');
observer.next(access);
observer.complete();
});
}
}
public register(credentials) {
if (credentials.email === null || credentials.password === null) {
return Observable.throw("Please insert credentials");
} else {
// At this point store the credentials to your backend!
return Observable.create(observer => {
observer.next(true);
observer.complete();
});
}
}
public getUserInfo() : User {
return this.currentUser;
}

public logout() {
return Observable.create(observer => {
this.currentUser = null;
observer.next(true);
observer.complete();
});
}
}

登录.ts

import { Component } from '@angular/core';
import { NavController, AlertController, LoadingController, Loading, IonicPage } from 'ionic-angular';
import { AuthServiceProvider } from '../providers/auth-service/auth-service';

@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
loading: Loading;
registerCredentials = { email: '', password: '' };

constructor(private nav: NavController, private auth: AuthServiceProvider, private alertCtrl: AlertController, private loadingCtrl: LoadingController) { }

public createAccount() {
this.nav.push('RegisterPage');
}

public login() {
this.showLoading()
this.auth.login(this.registerCredentials).subscribe(allowed => {
if (allowed) {
this.nav.setRoot('HomePage');
} else {
this.showError("Access Denied");
}
},
error => {
this.showError(error);
});
}

showLoading() {
this.loading = this.loadingCtrl.create({
content: 'Please wait...',
dismissOnPageChange: true
});
this.loading.present();
}

showError(text) {
this.loading.dismiss();

let alert = this.alertCtrl.create({
title: 'Fail',
subTitle: text,
buttons: ['OK']
});
alert.present(prompt);
}
}

截图程序结构:
ScreenShot Program structure

最佳答案

从您的项目结构来看,您的 login.ts 位于 login 文件夹中,而 login 文件夹位于 pages 文件夹中。

所以为了到达providers文件夹,你需要这样写

'../../providers/auth-service/auth-service'

这应该将您移出两个应该可以解决问题的文件夹。

关于angular - ionic 找不到模块 '../providers/auth-service/auth-service',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44225905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com