我正在尝试实现登录功能。
Login.ts
import {Component} from "@angular/core";
import {Header} from '../header/header';
import {AuthenticationService, User} from '../../services/authService'
import {DetailsPage} from '../details/details';
import {UserProfilePage} from '../userprofile/userprofile';
import {NavController,NavParams} from 'ionic-angular';
import {NgIf} from '@angular/common';
@Component({
templateUrl: 'build/pages/login/login.html',
directives:[Header],
providers: [AuthenticationService],
styles:[' .login-home { align:center;margin-left:20px;}']
})
export class LoginPage {
public user = new User('','');
public errorMsg = '';
public pageHeader:string;
constructor(
private _service:AuthenticationService,private nav: NavController) {
this.pageHeader="Login"
this.user = new User('','');
this.nav = nav;
}
login() {
this.nav.setRoot(DetailsPage);
this.nav.push(DetailsPage);
// let loginSucessful = this._service.login(this.user)
/** if(loginSucessful !== undefined && loginSucessful == false){
this.errorMsg = 'Invalid login';
}*/
}
}
详情页面如下 -
import {Component,OnInit} from "@angular/core";
import {Header} from '../header/header';
import {HomePage} from '../home/home';
import {AuthenticationService, User} from '../../services/authService'
import {NavController,NavParams,Platform,Storage,SqlStorage,Toast} from 'ionic-angular';
import {NgIf} from '@angular/common';
import {PersonSO} from '../../services/personSO';
@Component({
templateUrl: 'build/pages/userprofile/userprofile.html',
directives:[Header],
providers: [AuthenticationService]
})
export class DetailsPage implements OnInit{
public pageHeader:string;
public storage;
public people =[];
constructor(private platform: Platform,private navParams: NavParams,
private _service:AuthenticationService,private nav: NavController) {
this.pageHeader="List of user";
this.platform.ready().then(() => {
this.storage = new Storage(SqlStorage);
this.nav = nav;
});
}
ngOnInit() {
this._service.checkCredentials();
}
goBack(){
this.nav.push(HomePage);
}
navigateToUserForm(){
this.nav.push(HomePage);
}
edit(person:PersonSO){
this.nav.push(HomePage,{
person: person
});
}
}
如果我转到主页的详细信息页面,这工作正常。但是从登录页面导航时。我收到了以下错误
11 756293错误未捕获EXCEPTION:构建中的错误/ pages / login / login.html:17:20原始异常:TypeError: 无法读取未定义的ORIGINAL STACKTRACE的属性'参数': TypeError:无法读取未定义的属性“参数” 在ReflectionCapabilities.parameters(http://localhost:8100/build/js/app.bundle.js:29733:40) 在Reflector.parameters(http://localhost:8100/build/js/app.bundle.js:29921:48) 在CompileMetadataResolver.getDependenciesMetadata(http://localhost:8100/build/js/app.bundle.js:11007:86) 在CompileMetadataResolver.getTypeMetadata(http://localhost:8100/build/js/app.bundle.js:10958:26) 在http://localhost:8100/build/js/app.bundle.js:11107:30 在Array.map(本机) 在CompileMetadataResolver.getProvidersMetadata(http://localhost:8100/build/js/app.bundle.js:11095:26) 在CompileMetadataResolver.getDirectiveMetadata(http://localhost:8100/build/js/app.bundle.js:10910:34) 在RuntimeCompiler.resolveComponent(http://localhost:8100/build/js/app.bundle.js:14802:47) 在NavController.loadPage(http://localhost:8100/build/js/app.bundle.js:46890:24)错误 背景:
如果您有任何解决方案,请告诉我。
答案 0 :(得分:0)
非常确定这里有错误
@Component({
templateUrl: 'build/pages/login/login.html',
您的templateUrl
不应该从构建文件夹中调用。
@Component({
templateUrl: 'login.html',
您可以使用离子CLI
查看离子构建页面结构>_ ionic generate page login
然后需要在app文件夹的app.module.ts
文件中定义页面。