i want to check a checkbox and even if the page is refreshed i want the state of checkbox(enable or disable previously)must be same and only after the user change the state of checkbox it should be undone.
checkbox enable disable on users will in angular
Collapse
X
-
Code:<form [formGroup]="paymentdetailForm" class="form-horizontal" (ngSubmit)="onSubmit()"> <input type="checkbox" style="margin-top: 20px" formControlName="status" (click)="checkclick()" > <b>Enable Razorpay Payment</b> <div *ngIf="paymentdetailForm.controls.status.value"> <div class="radio"> <label> <input type="radio" name="" formControlName="payment_mode" [value]="1" (click)="setradio('1')" [checked]='true' >Test </label> </div> <div class="radio"> <label> <input formControlName="payment_mode" type="radio" [value]="2" (click)="setradio('2')" > Live </label> </div> <div class="form-group" *ngIf="isSelected('1')" > Test Key : <input type="text" class="form-control" formControlName="key_id" [(ngModel)] = "key_id"/> <input type="text" formControlName="id" hidden/> Test SlatKey : <input type="text" class="form-control" formControlName="salt_key" [(ngModel)] = "salt_key"/> </div> <div class="form-group" *ngIf="isSelected('2')"> Live Key : <input class="form-control" type="text" formControlName="key_id"/> Live SlatKey : <input type="text" class="form-control" formControlName="salt_key"/> </div> <button type="submit" class="btn btn-primary" style="background:#051f71; margin-left: 12px; margin-top: 50px;">Submit</button> </div> </form>Comment
-
so as far as i understand your question - you want to make the state of a checkbox persistent across user sessions?
If so - then there are several other questions. Is the (or a) user logged in? Then you would need to make it persistent for that specific user.
If not - do you expect a PC (or other device) is used by only 1 user? This might decide if the persistence is good or not.
There are different ways to achieve that:
1. store the state on your server in a session or database (depending on how long the persistence should be)
2. store state clientside in a cookie or local storage
PS: if a user logs in from another machine and you want the checkbox still being in that state - then option 1. and storing in a database is the only way to go - so what i want to say is that a solution depends on specific requirements - but for each of them there will be a solution.Last edited by gits; Jan 17 '20, 01:52 PM.Comment
Comment