Angular 6 checkbox triggers change when ngModel value is true
up vote
0
down vote
favorite
I have ngFor and inside I have checkbox.
<input type="checkbox" name="checkbox-{{i}}"
(change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
clickOn() event triggers, when test.fav value is true. Anybody used to have this problem? Regards.
angular checkbox angular6 angular-ngmodel
add a comment |
up vote
0
down vote
favorite
I have ngFor and inside I have checkbox.
<input type="checkbox" name="checkbox-{{i}}"
(change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
clickOn() event triggers, when test.fav value is true. Anybody used to have this problem? Regards.
angular checkbox angular6 angular-ngmodel
Do you mean it doesn't fire angModelChange
event when value isfalse
?
– Pankaj Parkar
Nov 10 at 14:24
Or that it triggers initially, wihout any user action?
– ConnorsFan
Nov 10 at 14:24
@PankajParkar I had to say (change). (change) function fires when checkbox ngModel value is true.
– KoboldMines
Nov 10 at 14:30
It triggers regardles of value.
– ritaj
Nov 10 at 14:36
@KoboldMines can you please provide me a stackblitz with reproducible problem?
– Pankaj Parkar
Nov 10 at 15:02
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have ngFor and inside I have checkbox.
<input type="checkbox" name="checkbox-{{i}}"
(change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
clickOn() event triggers, when test.fav value is true. Anybody used to have this problem? Regards.
angular checkbox angular6 angular-ngmodel
I have ngFor and inside I have checkbox.
<input type="checkbox" name="checkbox-{{i}}"
(change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
clickOn() event triggers, when test.fav value is true. Anybody used to have this problem? Regards.
angular checkbox angular6 angular-ngmodel
angular checkbox angular6 angular-ngmodel
edited Nov 10 at 17:19
HDJEMAI
4,068143654
4,068143654
asked Nov 10 at 14:20
KoboldMines
376
376
Do you mean it doesn't fire angModelChange
event when value isfalse
?
– Pankaj Parkar
Nov 10 at 14:24
Or that it triggers initially, wihout any user action?
– ConnorsFan
Nov 10 at 14:24
@PankajParkar I had to say (change). (change) function fires when checkbox ngModel value is true.
– KoboldMines
Nov 10 at 14:30
It triggers regardles of value.
– ritaj
Nov 10 at 14:36
@KoboldMines can you please provide me a stackblitz with reproducible problem?
– Pankaj Parkar
Nov 10 at 15:02
add a comment |
Do you mean it doesn't fire angModelChange
event when value isfalse
?
– Pankaj Parkar
Nov 10 at 14:24
Or that it triggers initially, wihout any user action?
– ConnorsFan
Nov 10 at 14:24
@PankajParkar I had to say (change). (change) function fires when checkbox ngModel value is true.
– KoboldMines
Nov 10 at 14:30
It triggers regardles of value.
– ritaj
Nov 10 at 14:36
@KoboldMines can you please provide me a stackblitz with reproducible problem?
– Pankaj Parkar
Nov 10 at 15:02
Do you mean it doesn't fire a
ngModelChange
event when value is false
?– Pankaj Parkar
Nov 10 at 14:24
Do you mean it doesn't fire a
ngModelChange
event when value is false
?– Pankaj Parkar
Nov 10 at 14:24
Or that it triggers initially, wihout any user action?
– ConnorsFan
Nov 10 at 14:24
Or that it triggers initially, wihout any user action?
– ConnorsFan
Nov 10 at 14:24
@PankajParkar I had to say (change). (change) function fires when checkbox ngModel value is true.
– KoboldMines
Nov 10 at 14:30
@PankajParkar I had to say (change). (change) function fires when checkbox ngModel value is true.
– KoboldMines
Nov 10 at 14:30
It triggers regardles of value.
– ritaj
Nov 10 at 14:36
It triggers regardles of value.
– ritaj
Nov 10 at 14:36
@KoboldMines can you please provide me a stackblitz with reproducible problem?
– Pankaj Parkar
Nov 10 at 15:02
@KoboldMines can you please provide me a stackblitz with reproducible problem?
– Pankaj Parkar
Nov 10 at 15:02
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Use reference
of checkbox element and pass the value or use ngModelChange
Replace the below code
<input type="checkbox" name="checkbox-{{i}}" (change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
by
<input type="checkbox" name="checkbox-{{i}}" #test
(change)="clickOn(test.value)" [(ngModel)]="test.fav" />
or
<input type="checkbox" name="checkbox-{{i}}" #test
(ngModelChange)="clickOn($event)" [(ngModel)]="test.fav" />
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Use reference
of checkbox element and pass the value or use ngModelChange
Replace the below code
<input type="checkbox" name="checkbox-{{i}}" (change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
by
<input type="checkbox" name="checkbox-{{i}}" #test
(change)="clickOn(test.value)" [(ngModel)]="test.fav" />
or
<input type="checkbox" name="checkbox-{{i}}" #test
(ngModelChange)="clickOn($event)" [(ngModel)]="test.fav" />
add a comment |
up vote
0
down vote
Use reference
of checkbox element and pass the value or use ngModelChange
Replace the below code
<input type="checkbox" name="checkbox-{{i}}" (change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
by
<input type="checkbox" name="checkbox-{{i}}" #test
(change)="clickOn(test.value)" [(ngModel)]="test.fav" />
or
<input type="checkbox" name="checkbox-{{i}}" #test
(ngModelChange)="clickOn($event)" [(ngModel)]="test.fav" />
add a comment |
up vote
0
down vote
up vote
0
down vote
Use reference
of checkbox element and pass the value or use ngModelChange
Replace the below code
<input type="checkbox" name="checkbox-{{i}}" (change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
by
<input type="checkbox" name="checkbox-{{i}}" #test
(change)="clickOn(test.value)" [(ngModel)]="test.fav" />
or
<input type="checkbox" name="checkbox-{{i}}" #test
(ngModelChange)="clickOn($event)" [(ngModel)]="test.fav" />
Use reference
of checkbox element and pass the value or use ngModelChange
Replace the below code
<input type="checkbox" name="checkbox-{{i}}" (change)="clickOn(test.fav)" [(ngModel)]="test.fav" />
by
<input type="checkbox" name="checkbox-{{i}}" #test
(change)="clickOn(test.value)" [(ngModel)]="test.fav" />
or
<input type="checkbox" name="checkbox-{{i}}" #test
(ngModelChange)="clickOn($event)" [(ngModel)]="test.fav" />
answered Nov 10 at 16:42
Sunil Singh
5,5971625
5,5971625
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53239859%2fangular-6-checkbox-triggers-change-when-ngmodel-value-is-true%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
Do you mean it doesn't fire a
ngModelChange
event when value isfalse
?– Pankaj Parkar
Nov 10 at 14:24
Or that it triggers initially, wihout any user action?
– ConnorsFan
Nov 10 at 14:24
@PankajParkar I had to say (change). (change) function fires when checkbox ngModel value is true.
– KoboldMines
Nov 10 at 14:30
It triggers regardles of value.
– ritaj
Nov 10 at 14:36
@KoboldMines can you please provide me a stackblitz with reproducible problem?
– Pankaj Parkar
Nov 10 at 15:02