如何停止自动页面重定向离子2

时间:2017-06-28 04:06:14

标签: angular cordova ionic2

我正在使用离子2。

我使用了表格

这是我的代码。

<form [formGroup]="Editflat"  novalidate>
         <ion-item>
             <ion-label floating>About flat</ion-label>
             <ion-textarea class="textareadesc" elastic formControlName="ABOUT_FLAT">
             </ion-textarea>
        </ion-item>
        <ion-item>
             <ion-label floating>Area</ion-label>
             <ion-input type="text" formControlName="AREA"></ion-input>
        </ion-item>
         <ion-item>
             <ion-label floating>BHK</ion-label>
             <ion-input type="text" formControlName="BHK"></ion-input>
        </ion-item>
        <ion-item >
             <ion-label floating>Rent Amount</ion-label>
             <ion-input type="text" formControlName="RENT_AMOUNT"></ion-input>
        </ion-item>
        <ion-item >
             <ion-label floating>Sale Amount</ion-label>
             <ion-input type="text" formControlName="SALE_AMOUNT"></ion-input>
        </ion-item>
        <ion-item class="check">
              <ion-label>Rent</ion-label>
              <ion-checkbox  checked="{{rent}}" (ionChange)="change($event)"></ion-checkbox>
         </ion-item>
       <ion-item class="check">
              <ion-label>Sale</ion-label>
              <ion-checkbox  checked="{{sale}}" (ionChange)="change($event)"></ion-checkbox>
         </ion-item>
       <ion-item>
          <ion-label floating>Current rent amount</ion-label>
           <ion-input type="text" formControlName="CURRENT_RENTAMOUNT"></ion-input>
       </ion-item>
      <div class="btn"  (click)="Submit(Editflat,images,$event)">
             <button ion-button full>Update</button>
      </div>
</form>

这是我的提交功能

Submit(value,imagevalue,event)

{

//event.stopPropagation();

this.platform.ready().then(() => {
          window.plugins.toast.show("Please wait...", "short",'bottom',3000);
    });
var imagevalue1=imagevalue;
var Result =  moment().format('YYYY-MM-DD HH:mm:ss');
this.Editflat.controls['UPDATEDDATE'].setValue(Result); 
 var f=this.af.database.list('/flats');
 f.update(this.key,this.Editflat.value);

 //Send notification to tenant

 if(this.Editflat.value.TENANT_EXIST == '1')
{
  var id=this.Editflat.value.TENANT_ID;
  var filter=this.apartmentuser.filter(a=>a.USER_ID.toString() == id.toString());
  var E=filter[0].EMAIL;
  var Mob=filter[0].MOBILE1;
  var M=this.message2;
  var s=this.Addform.value.TYPE;
  var n1=filter[0].FIRST_NAME + filter[0].LAST_NAME;

  //Send Email

  this.authservice.sendEmail(n1,E,M,s).subscribe(data=>{
        console.log(data);
      })

  //Send SMS

  this.authservice.SendSms(Mob,M).subscribe(data=>{
  console.log(data);
}); 

}

  for(var i1 in this.Managementadmin)
  {

    //Get Current Date

    var Result =  moment().format('YYYY-MM-DD HH:mm:ss'); 
    var s=this.Managementadmin[i1].USER_ID.toString();
    this.Addform.controls['TO'].setValue(s);
    this.Addform.controls['SEND_TIME'].setValue(Result); 
    var M=this.message2;
    this.Addform.controls['MSG'].setValue(M); 
    var n=this.af.database.list('/notifications');
    n.push(this.Addform.value);
      // this.sendnotifications.push(this.Addform.value);
    var E=this.Managementadmin[i1].EMAIL;
    var NAME=this.Managementadmin[i1].FIRST_NAME + this.Managementadmin[i1].LAST_NAME;
    var Subject=this.Addform.value.TYPE;
    this.authservice.sendEmail(NAME,E,M,Subject).subscribe(data=>{
        console.log(data);
      })

  }

var NUM=this.Numberval;
var M1=this.message2;
this.authservice.SendSms(NUM,M1).subscribe(data=>{
  console.log(data);
});

      var path1=[];
      for(var i in imagevalue1)
      {
       console.log();
       if(imagevalue1[i].file)
       {
         //console.log("Image File : " +imagevalue1[i].file );


         // convert base64 to raw binary data held in a string
        // doesn't handle URLEncoded DataURIs - see stack overflow answer #6850276 for code that does this
        var byteString = atob(imagevalue1[i].file.split(',')[1]);

        // separate out the mime component
        var mimeString = imagevalue1[i].file.split(',')[0].split(':')[1].split(';')[0]

        // write the bytes of the string to an ArrayBuffer
        var ab = new ArrayBuffer(byteString.length);
        var ia = new Uint8Array(ab);
        for (var j = 0; j < byteString.length; j++) {
          ia[j] = byteString.charCodeAt(j);
        }

        // write the ArrayBuffer to a blob
        var blob = new Blob([ab], {type: mimeString});
        console.log("Blob");
        console.log(blob);

         var fileName = 'sample-' + new Date().getTime() + '.jpg';
        var storageRef = this.firebase.storage().ref('flats/'+fileName); 
          storageRef.put(blob).then((snapshot) => {
              var img1url = snapshot.downloadURL;
              path1.push({
               path:img1url});
            var flatvalue=this.af.database.list('/flats');
            flatvalue.update(this.key,{FLAT_IMAGES:path1})

            })
       }
        //if(this.images[i].path)
         else if(imagevalue1[i].path)
         {
            console.log("image value of path:" + imagevalue1[i].path);
            path1.push({
              path:imagevalue1[i].path
            })
            var flatvalue=this.af.database.list('/flats');
           flatvalue.update(this.key,{FLAT_IMAGES:path1})

          }
        }

        if(imagevalue1.length == 0)
         {
            console.log("image values are null")
            var flatvalue=this.af.database.list('/flats');
            flatvalue.update(this.key,{FLAT_IMAGES:""})
         } 


       this.platform.ready().then(() => {
          window.plugins.toast.show("Updated success", "short",'bottom',3000);
    }); 
  return false;

}

我的根页是dashboard.ts。 我将按钮页面重定向到根页面。 但是我没有在页面重定向中编写任何代码。

请建议我,

由于

1 个答案:

答案 0 :(得分:1)

问题:

您已将click事件放在div (click)="Submit(Editflat,images,$event)"上,他如何知道$ event是用于提交,click事件应该是按钮不在div上,并且还使其类型提交

<button ion-button full type='submit' (click)="Submit(Editflat,images,$event)">Update</button>

然后尝试使用您的代码,如果它仍然不起作用,只需将return false放在提交功能中,

Submit(value,imagevalue,event)
{
   // event.preventDefault();
   return false;
}