@asha4640 wrote:
my html page
<form [formGroup]="registerForm"> <ion-card *ngFor="let user of (test)?.results"> <ion-item> <ion-label floating>Name</ion-label> <ion-input formControlName="name" type="text" value="{{ user.name }}"></ion-input> </ion-item> <ion-item> <ion-label floating>Username</ion-label> <ion-input formControlName="username" type="text" value="{{ user.username }}"></ion-input> </ion-item> <ion-item> <ion-label floating>Password</ion-label> <ion-input formControlName="password" type="text" value="{{ user.password }}"></ion-input> </ion-item> </ion-card> <ion-button expand="full" (click)="update()">Update</ion-button> </form>ts file
update(){
this.registerForm.patchValue({ name_new:this.registerForm.value.name, username_new:this.registerForm.value.username, password_new:this.registerForm.value.password});
let id = this.activatedRoute.snapshot.paramMap.get('id'); var link = 'http://localhost/curdForm/index.php/Login/update'; var myData = JSON.stringify({name:this.name_new,username: this.username_new,password:this.password_new,id:id}); this.http.post(link, myData) .subscribe(data => { this.data.response = data["_body"]; console.log("success!"); if(this.data.response==null){ alert("Not Updated"); } else{ this.navCtrl.navigateForward('admin'); } }, error => { console.log("Oooops!"); });}
I need to update the form values. If the form values not changed and click the button, then text values become null values. I need the original value of text field from the form, if it’s not changed.
Posts: 1
Participants: 1