【发布时间】:2019-02-05 19:24:46
【问题描述】:
我正在开发 Ionic 4,并试图了解它的基本概念。所以我遇到了我目前正在使用的应用程序的问题。
它的一个功能是显示用户的信息,除了两个变量外,一切都正确显示。
这是我的页面.ts的一部分
ngOnInit() {
this.slug = this.route.snapshot.paramMap.get('id');
this.loadData(); }
loadData() {
if (this.dataService.loaded) {
this.userList = this.dataService.getUserlist(this.slug);
} else {
this.dataService.load().then(() => {
this.userList = this.dataService.getUserlist(this.slug);
});
}}
...
displayActvLvl(): string {
let temp: string;
let val: number;
val = this.userList.actLvlVal;
if (val === 1.2) {
temp = 'No Active';
} else if (val === 1.375) {
temp = 'Lightly Act';
} else if (val === 1.55) {
temp = 'Moderate Active';
} else if (val === 1.75) {
temp = 'Very Active';
} else if (val === 1.9) {
temp = 'Athlete';
}
return temp;}
displayGender(): string {
if (this.userList.gender) {
return 'Female';
} else {
return 'Male';
} }
这是没有显示信息的两项
<ion-row>
<ion-col size="6">
<ion-item text-center>
<ion-label position="stacked">{{displayGender()}}</ion-label>
<ion-note>Gender</ion-note>
</ion-item>
</ion-col>
<ion-col size="6">
<ion-item text-center>
<ion-label position="stacked">{{displayActvLvl()}}</ion-label>
<ion-note>Activity Level</ion-note>
</ion-item>
</ion-col>
</ion-row>
我知道这个问题,但我无法找到解决方案。据我了解,当从数据服务加载数据,然后页面初始化时,这两个函数运行但两个项目不会自行刷新。有什么帮助吗?
这是来自数据服务的加载函数
load(): Promise<boolean> {
return Promise.resolve(true);
} 编辑: 数据服务中的 GetUserList 函数
getUserlist(id): UserInfo { return this.userList.find(userinfo => userinfo.id === id);}
【问题讨论】:
-
您能否分享一下您的 DataService 中的 getUserlist() 函数代码?
-
@ZearaeZ 我把它放在主帖上
标签: angular ionic-framework ionic4