我正在尝试构建一个交互,通过推送它并包含要编辑的配置文件,我可以从配置文件页面转到单独的编辑配置文件页面。但是,我间歇性地得到TypeError
说应用程序无法找到传递的profile
对象中预期的元素。
以下是完整错误:
Error: Uncaught (in promise): TypeError: Cannot read property 'about_me' of undefined
TypeError: Cannot read property 'about_me' of undefined
at Object.eval [as updateDirectives] (ng:///AppModule/EditProfilePage.ngfactory.js:510:34)
at Object.debugUpdateDirectives [as updateDirectives] (http://localhost:8100/build/vendor.js:15003:21)
at checkAndUpdateView (http://localhost:8100/build/vendor.js:14172:14)
at callViewAction (http://localhost:8100/build/vendor.js:14522:21)
at execComponentViewsAction (http://localhost:8100/build/vendor.js:14454:13)
at checkAndUpdateView (http://localhost:8100/build/vendor.js:14178:5)
at callWithDebugContext (http://localhost:8100/build/vendor.js:15404:42)
at Object.debugCheckAndUpdateView [as checkAndUpdateView] (http://localhost:8100/build/vendor.js:14941:12)
at ViewRef_.detectChanges (http://localhost:8100/build/vendor.js:11964:18)
at Tab.NavControllerBase._viewAttachToDOM (http://localhost:8100/build/vendor.js:50138:40)
at c (http://localhost:8100/build/polyfills.js:3:19752)
at Object.reject (http://localhost:8100/build/polyfills.js:3:19174)
at Tab.NavControllerBase._fireError (http://localhost:8100/build/vendor.js:49901:16)
at Tab.NavControllerBase._failed (http://localhost:8100/build/vendor.js:49894:14)
at http://localhost:8100/build/vendor.js:49941:59
at t.invoke (http://localhost:8100/build/polyfills.js:3:14976)
at Object.onInvoke (http://localhost:8100/build/vendor.js:5293:33)
at t.invoke (http://localhost:8100/build/polyfills.js:3:14916)
at r.run (http://localhost:8100/build/polyfills.js:3:10143)
at http://localhost:8100/build/polyfills.js:3:20242
这是个人资料页面上的html元素:
<button class="edit-profile" *ngIf="isCurrentUser" ion-item (click)="editProfile(profile)" detail-none><ion-icon name="create-outline"></ion-icon> Edit Profile</button>
这是方法:
editProfile(person: Person) {
this.navCtrl.push(EditProfilePage, person);
}
这是编辑个人资料页面的组成部分:
export class EditProfilePage {
profile: Person;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.profile = navParams.data;
console.log(navParams.data);
}
ionViewDidLoad() {
console.log('ionViewDidLoad EditProfilePage');
console.log(this.profile);
}
}
答案 0 :(得分:1)
如果配置文件未定义,则编辑该配置文件
editProfile(person: Person) {
if(person)
this.navCtrl.push(EditProfilePage, person);
}