On change of checkbox state remain same in UI
up vote
1
down vote
favorite
<input type="checkbox" [(ngModel)]="rowData.is_permitted" (change)="changeStatus()">
changeStatus() {
rowData.is_permitted = true;
}
If I uncheck checkbox but conditionally I want to select the checkbox, the flag updated but not affect in UI.
javascript angular html5 typescript checkbox
add a comment |
up vote
1
down vote
favorite
<input type="checkbox" [(ngModel)]="rowData.is_permitted" (change)="changeStatus()">
changeStatus() {
rowData.is_permitted = true;
}
If I uncheck checkbox but conditionally I want to select the checkbox, the flag updated but not affect in UI.
javascript angular html5 typescript checkbox
what is not working ?
– Sunil Singh
Nov 17 at 9:05
Its working as expected. Check here stackblitz.com/edit/angular-1vmnl2
– Sunil Singh
Nov 17 at 9:06
It doesn't (when you click onChange
label.
– Alon Shmiel
Nov 17 at 9:08
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
<input type="checkbox" [(ngModel)]="rowData.is_permitted" (change)="changeStatus()">
changeStatus() {
rowData.is_permitted = true;
}
If I uncheck checkbox but conditionally I want to select the checkbox, the flag updated but not affect in UI.
javascript angular html5 typescript checkbox
<input type="checkbox" [(ngModel)]="rowData.is_permitted" (change)="changeStatus()">
changeStatus() {
rowData.is_permitted = true;
}
If I uncheck checkbox but conditionally I want to select the checkbox, the flag updated but not affect in UI.
javascript angular html5 typescript checkbox
javascript angular html5 typescript checkbox
asked Nov 17 at 8:57
Shubham Ghormade
276
276
what is not working ?
– Sunil Singh
Nov 17 at 9:05
Its working as expected. Check here stackblitz.com/edit/angular-1vmnl2
– Sunil Singh
Nov 17 at 9:06
It doesn't (when you click onChange
label.
– Alon Shmiel
Nov 17 at 9:08
add a comment |
what is not working ?
– Sunil Singh
Nov 17 at 9:05
Its working as expected. Check here stackblitz.com/edit/angular-1vmnl2
– Sunil Singh
Nov 17 at 9:06
It doesn't (when you click onChange
label.
– Alon Shmiel
Nov 17 at 9:08
what is not working ?
– Sunil Singh
Nov 17 at 9:05
what is not working ?
– Sunil Singh
Nov 17 at 9:05
Its working as expected. Check here stackblitz.com/edit/angular-1vmnl2
– Sunil Singh
Nov 17 at 9:06
Its working as expected. Check here stackblitz.com/edit/angular-1vmnl2
– Sunil Singh
Nov 17 at 9:06
It doesn't (when you click on
Change
label.– Alon Shmiel
Nov 17 at 9:08
It doesn't (when you click on
Change
label.– Alon Shmiel
Nov 17 at 9:08
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
The problem is shown in this stackblitz. After unchecking the checkbox, the value is set to true
in code but the checkbox remains unchecked.
You can do the following to override the action of the user with a change in code:
- Force an immediate change detection by calling
ChangeDetectorRef.detectChanges
- Set the value to
true
- Let the change detection mecanism update the checkbox to reflect the updated value
In the code below, I handle the ngModelChange
event. The conditional behavior mentioned in the question is simulated with the keepChecked
property:
<input type="checkbox"
[(ngModel)]="rowData.is_permitted"
(ngModelChange)="changeStatus()">
changeStatus() {
if (this.keepChecked) {
this.changeDetectorRef.detectChanges();
this.rowData.is_permitted = true;
}
}
See this stackblitz for a demo.
A similar result could be obtained by setting the value asynchronously in a setTimeout
callback:
changeStatus() {
if (this.keepChecked) {
setTimeout(() => {
this.rowData.is_permitted = true;
});
}
}
but I prefer to keep the code synchronous by calling ChangeDetectorRef.detectChanges
.
add a comment |
up vote
0
down vote
If I understand your question,
After changing the input, it remains true.
So, when rowData.is_permitted
is true, you need to make it false.
rowData.is_permitted
is false, you need to make it true.
If this is your problem, try do it by changing changeStatus
function:
rowData.is_permitted = !rowData.is_permitted;
rowData.is_permitted will get the opposite value.
Working example that I forked from @SunilSingh is here
add a comment |
up vote
0
down vote
You have to change ngModel value on click. May be rowData.is_permitted
default value is true
so, on click it is not changed by your function.
Your changeStatus function will be
changeStatus() {
rowData.is_permitted = !rowData.is_permitted;
}
New contributor
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The problem is shown in this stackblitz. After unchecking the checkbox, the value is set to true
in code but the checkbox remains unchecked.
You can do the following to override the action of the user with a change in code:
- Force an immediate change detection by calling
ChangeDetectorRef.detectChanges
- Set the value to
true
- Let the change detection mecanism update the checkbox to reflect the updated value
In the code below, I handle the ngModelChange
event. The conditional behavior mentioned in the question is simulated with the keepChecked
property:
<input type="checkbox"
[(ngModel)]="rowData.is_permitted"
(ngModelChange)="changeStatus()">
changeStatus() {
if (this.keepChecked) {
this.changeDetectorRef.detectChanges();
this.rowData.is_permitted = true;
}
}
See this stackblitz for a demo.
A similar result could be obtained by setting the value asynchronously in a setTimeout
callback:
changeStatus() {
if (this.keepChecked) {
setTimeout(() => {
this.rowData.is_permitted = true;
});
}
}
but I prefer to keep the code synchronous by calling ChangeDetectorRef.detectChanges
.
add a comment |
up vote
1
down vote
accepted
The problem is shown in this stackblitz. After unchecking the checkbox, the value is set to true
in code but the checkbox remains unchecked.
You can do the following to override the action of the user with a change in code:
- Force an immediate change detection by calling
ChangeDetectorRef.detectChanges
- Set the value to
true
- Let the change detection mecanism update the checkbox to reflect the updated value
In the code below, I handle the ngModelChange
event. The conditional behavior mentioned in the question is simulated with the keepChecked
property:
<input type="checkbox"
[(ngModel)]="rowData.is_permitted"
(ngModelChange)="changeStatus()">
changeStatus() {
if (this.keepChecked) {
this.changeDetectorRef.detectChanges();
this.rowData.is_permitted = true;
}
}
See this stackblitz for a demo.
A similar result could be obtained by setting the value asynchronously in a setTimeout
callback:
changeStatus() {
if (this.keepChecked) {
setTimeout(() => {
this.rowData.is_permitted = true;
});
}
}
but I prefer to keep the code synchronous by calling ChangeDetectorRef.detectChanges
.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The problem is shown in this stackblitz. After unchecking the checkbox, the value is set to true
in code but the checkbox remains unchecked.
You can do the following to override the action of the user with a change in code:
- Force an immediate change detection by calling
ChangeDetectorRef.detectChanges
- Set the value to
true
- Let the change detection mecanism update the checkbox to reflect the updated value
In the code below, I handle the ngModelChange
event. The conditional behavior mentioned in the question is simulated with the keepChecked
property:
<input type="checkbox"
[(ngModel)]="rowData.is_permitted"
(ngModelChange)="changeStatus()">
changeStatus() {
if (this.keepChecked) {
this.changeDetectorRef.detectChanges();
this.rowData.is_permitted = true;
}
}
See this stackblitz for a demo.
A similar result could be obtained by setting the value asynchronously in a setTimeout
callback:
changeStatus() {
if (this.keepChecked) {
setTimeout(() => {
this.rowData.is_permitted = true;
});
}
}
but I prefer to keep the code synchronous by calling ChangeDetectorRef.detectChanges
.
The problem is shown in this stackblitz. After unchecking the checkbox, the value is set to true
in code but the checkbox remains unchecked.
You can do the following to override the action of the user with a change in code:
- Force an immediate change detection by calling
ChangeDetectorRef.detectChanges
- Set the value to
true
- Let the change detection mecanism update the checkbox to reflect the updated value
In the code below, I handle the ngModelChange
event. The conditional behavior mentioned in the question is simulated with the keepChecked
property:
<input type="checkbox"
[(ngModel)]="rowData.is_permitted"
(ngModelChange)="changeStatus()">
changeStatus() {
if (this.keepChecked) {
this.changeDetectorRef.detectChanges();
this.rowData.is_permitted = true;
}
}
See this stackblitz for a demo.
A similar result could be obtained by setting the value asynchronously in a setTimeout
callback:
changeStatus() {
if (this.keepChecked) {
setTimeout(() => {
this.rowData.is_permitted = true;
});
}
}
but I prefer to keep the code synchronous by calling ChangeDetectorRef.detectChanges
.
edited Nov 17 at 15:11
answered Nov 17 at 14:00
ConnorsFan
28k42457
28k42457
add a comment |
add a comment |
up vote
0
down vote
If I understand your question,
After changing the input, it remains true.
So, when rowData.is_permitted
is true, you need to make it false.
rowData.is_permitted
is false, you need to make it true.
If this is your problem, try do it by changing changeStatus
function:
rowData.is_permitted = !rowData.is_permitted;
rowData.is_permitted will get the opposite value.
Working example that I forked from @SunilSingh is here
add a comment |
up vote
0
down vote
If I understand your question,
After changing the input, it remains true.
So, when rowData.is_permitted
is true, you need to make it false.
rowData.is_permitted
is false, you need to make it true.
If this is your problem, try do it by changing changeStatus
function:
rowData.is_permitted = !rowData.is_permitted;
rowData.is_permitted will get the opposite value.
Working example that I forked from @SunilSingh is here
add a comment |
up vote
0
down vote
up vote
0
down vote
If I understand your question,
After changing the input, it remains true.
So, when rowData.is_permitted
is true, you need to make it false.
rowData.is_permitted
is false, you need to make it true.
If this is your problem, try do it by changing changeStatus
function:
rowData.is_permitted = !rowData.is_permitted;
rowData.is_permitted will get the opposite value.
Working example that I forked from @SunilSingh is here
If I understand your question,
After changing the input, it remains true.
So, when rowData.is_permitted
is true, you need to make it false.
rowData.is_permitted
is false, you need to make it true.
If this is your problem, try do it by changing changeStatus
function:
rowData.is_permitted = !rowData.is_permitted;
rowData.is_permitted will get the opposite value.
Working example that I forked from @SunilSingh is here
answered Nov 17 at 9:07
Alon Shmiel
1,0781565113
1,0781565113
add a comment |
add a comment |
up vote
0
down vote
You have to change ngModel value on click. May be rowData.is_permitted
default value is true
so, on click it is not changed by your function.
Your changeStatus function will be
changeStatus() {
rowData.is_permitted = !rowData.is_permitted;
}
New contributor
add a comment |
up vote
0
down vote
You have to change ngModel value on click. May be rowData.is_permitted
default value is true
so, on click it is not changed by your function.
Your changeStatus function will be
changeStatus() {
rowData.is_permitted = !rowData.is_permitted;
}
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
You have to change ngModel value on click. May be rowData.is_permitted
default value is true
so, on click it is not changed by your function.
Your changeStatus function will be
changeStatus() {
rowData.is_permitted = !rowData.is_permitted;
}
New contributor
You have to change ngModel value on click. May be rowData.is_permitted
default value is true
so, on click it is not changed by your function.
Your changeStatus function will be
changeStatus() {
rowData.is_permitted = !rowData.is_permitted;
}
New contributor
edited Nov 17 at 10:03
Saqib Shahzad
534119
534119
New contributor
answered Nov 17 at 9:46
Shubham Keshari
444
444
New contributor
New contributor
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349706%2fon-change-of-checkbox-state-remain-same-in-ui%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what is not working ?
– Sunil Singh
Nov 17 at 9:05
Its working as expected. Check here stackblitz.com/edit/angular-1vmnl2
– Sunil Singh
Nov 17 at 9:06
It doesn't (when you click on
Change
label.– Alon Shmiel
Nov 17 at 9:08