【发布时间】:2017-05-10 14:38:51
【问题描述】:
我正在使用 ionic 2。我在 ionic 2 中面临很多问题。当我导航推送以显示数据时。第一次它工作正常。之后它在控制台中打印数据。但没有显示在屏幕上。
而且在终端中,当我对 .ts、.html、.scss 文件进行一些更改时。它没有更新。我需要关闭我的终端,然后我需要再次执行ionic serve --lab.. 那么是否将.ts 文件更改为.js。如果是,我需要更改新 .js 文件中的任何内容的语法吗?
谢谢, 萨蒂什
更新:
我有主屏幕,通过推送我传递 cat id 以根据我从 home.html 传递的猫 ID 在我的 settings.html 中填充数据:
我的home.html
<div class="item item-body no-padding" style="border-width: 0px !important;">
<div class="row no-padding" *ngFor="let data of Catdata;let i = index" (click)="showDetails(Catdata[i].CatID)">
<ng-container *ngIf=" i % 2 === 0">
<div class="col col-50 custom-design2" style="background: url(img url) no-repeat center;background-size: cover;">
<div class="custom-design1"><span class="grid-title">{{Catdata[i].CategoryName}}</span></div>
</div>
<div class="col col-50 custom-design2" style="background: url(img url) no-repeat center;background-size: cover;">
<div class="custom-design1"><span class="grid-title">{{Catdata[i+1].CategoryName}}</span></div>
</div>
</ng-container>
</div>
</div>
我的家.ts:
data: any;
Catdata: any;
constructor( public alertCtrl: AlertController,
public modalCtrl: ModalController,
public navCtrl: NavController,
public http:Http,
public authService: AuthService) {
this.submit();
}
submit() {
this.authService.categ(this.loginData).then((result) => {
this.data = result;
if(this.data.status == 1)
{
this.Catdata = this.data.CatgeoryList;
for(let i=0; i<this.Catdata.length; i++) {
console.log(this.Catdata[i].CategoryName);
}
}
else if(this.data.status == 0) {
let alert = this.alertCtrl.create({
title: 'Error',
subTitle: 'Please Enter Valid Username & Password',
buttons: ['OK']
});
alert.present();
}
}, (err) => {
});
}
public showDetails(catId: any): void {
this.navCtrl.push(SettingsPage, { clickedcatId: catId });
}
我的设置.html:
<div class="item item-body no-padding" style="border-width: 0px !important;">
<div class="row no-padding" *ngFor="let data of Catdata;let i = index" (click)="opndetailpage()">
<ng-container *ngIf=" i % 2 === 0">
<div class="col col-50 custom-design2" style="background: url(img url) no-repeat center;background-size: cover;">
<div class="custom-design1"><span class="grid-title">{{data[i].SubCategoryName}}</span></div>
</div>
<div class="col col-50 custom-design2" style="background: url(img url) no-repeat center;background-size: cover;">
<div class="custom-design1"><span class="grid-title">{{data[i+1].SubCategoryName}}</span></div>
</div>
</ng-container>
</div>
</div>
我的settings.ts
data: any;
Catdata: any;
constructor( public alertCtrl: AlertController,
public modalCtrl: ModalController,
public navCtrl: NavController,
public http:Http,
public authService: AuthService,private navParams: NavParams) {
this.categoryid = navParams.get('clickedcatId');
console.log(this.categoryid);
this.another();
}
another() {
this.subcatdata = { CatID:this.categoryid};
this.authService.subcatte(this.subcatdata).then((result) => {
this.data = result;
console.log (this.data);
if(this.data.status == 1)
{
this.Catdata = this.data.SubCatgeoryList;
for(let i=0; i<this.Catdata.length; i++) {
console.log(this.Catdata[i].SubCategoryName);
}
}
else if(this.data.status == 0) {
let alert = this.alertCtrl.create({
title: 'Error',
subTitle: 'Please Enter Valid Username & Password',
buttons: ['OK']
});
alert.present();
}
}, (err) => {
});
}
我的authservice.ts
这很好:
categ(cat: any) {
return new Promise((resolve, reject) => {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.http.post(apiUrl+'categories.php', JSON.stringify(cat), {headers: headers})
.subscribe(res => {
resolve(res.json());
}, (err) => {
reject(err);
});
});
}
subcatte(subcat: any) {
return new Promise((resolve, reject) => {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.http.post(apiUrl+'subcategory.php', JSON.stringify(subcat), {headers: headers})
.subscribe(res => {
resolve(res.json());
}, (err) => {
reject(err);
});
});
}
【问题讨论】:
-
我可以将 ionic2 .ts 文件更改为 .js 否 .. ionic 2 仅适用于 typescript。 当我做一些改变时。它没有更新 ..这是一个不同的问题。
-
ionic 会在您对任何文件进行更改后立即自动更新视图,这可能是因为您正在更改文件并保存,然后再次更改文件并保存,然后才能构建以前的保存状态。为了克服这个问题,您可能想尝试只输入空行并保存并让它构建应用程序的这种状态
-
@suraj 我发布了我的完整代码。我做错了什么。真的过去2天。我无法得到解决方案
-
@warl0ck 我发布了我的完整代码。我做错了什么。真的过去2天。我无法得到解决方案
-
你能告诉它什么时候没有更新数据/用户界面你是否在它还在构建应用程序时进行了更改并保存了?
标签: typescript ionic-framework ionic2