关于8-2 username undefined 错误
来源:

cathy_Cathy
2016-08-14
麻烦帮忙看一下问题在哪里,以下为代码
<ion-header>
<ion-navbar>
<ion-title>
用户中心
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding class="contact">
<ion-list>提问
<ion-item>
<ion-label stacked>用户名</ion-label>
<ion-input type="text" [(ngModel)]="user.username"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>password</ion-label>
<ion-input type="text"[(ngModel)]="user.password"></ion-input>
</ion-item>
</ion-list>
<button block (click)="login()">登录</button>
</ion-content>
import {Component} from '@angular/core';
import {NavController,Loading} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/contact/contact.html'
}
export class ContactPage {
public user = {
username : 'parry',
password :'';
}
constructor(private navCtrl: NavController) {
this.navCtrl = navCtrl;
}
login(){
console.log(this.user.username);
let loading = Loading.create({
content:"Please wait...",
duration: 3000,
dismissOnPageChange: true
});
this.navCtrl.present(loading);
}
}
一下为错误提示:
EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in build/pages/contact/contact.html:11:29
ORIGINAL EXCEPTION: TypeError: Cannot read property 'username' of undefined
ORIGINAL STACKTRACE:
TypeError: Cannot read property 'username' of undefined
at DebugAppView._View_ContactPage0.detectChangesInternal (ContactPage.template.js:328:36)
at DebugAppView.AppView.detectChanges (http://192.168.0.102:8100/build/js/app.bundle.js:31730:14)
at DebugAppView.detectChanges (http://192.168.0.102:8100/build/js/app.bundle.js:31835:44)
at DebugAppView.AppView.detectViewChildrenChanges (http://192.168.0.102:8100/build/js/app.bundle.js:31756:19)
at DebugAppView.AppView.detectChangesInternal (http://192.168.0.102:8100/build/js/app.bundle.js:31741:14)
at DebugAppView.AppView.detectChanges (http://192.168.0.102:8100/build/js/app.bundle.js:31730:14)
at DebugAppView.detectChanges (http://192.168.0.102:8100/build/js/app.bundle.js:31835:44)
at ViewRef_.detectChanges (http://192.168.0.102:8100/build/js/app.bundle.js:32187:65)
at ViewController.fireWillEnter (http://192.168.0.102:8100/build/js/app.bundle.js:61803:22)
at Tab.NavControllerBase._postRender (http://192.168.0.102:8100/build/js/app.bundle.js:60023:30)
ERROR CONTEXT:
[object Object]
1回答
-
Parry
2016-08-14
使用的 Ionic 版本是什么?
022016-08-14
相似问题