第二次打开时,离子视图未更新页面

时间:2017-05-08 10:38:43

标签: typescript ionic-framework ionic2

我正在使用离子2.我在离子2中面临很多问题。当我导航时显示数据。第一次它的工作正常。之后,它在控制台中打印数据。但没有在屏幕上显示。

并且在终端中,当我对.ts,.html,.scss文件进行一些更改时。它不会更新。我需要关闭我的终端,我需要再次ionic serve --lab ..所以.ts文件更改为.js。如果是,我需要更改新.js文件中的任何内容。

谢谢, Sathish所在

更新:

我有主屏幕并且通过推送我正在通过cat id根据我从home.html传递的cat 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>

我的家。:

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 });


    }

我的设置:

<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);
          });
    });
  }

0 个答案:

没有答案