Skip to content

Commit

Permalink
fix(module: checkbox): fix checkbox init status when checked is true (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fisherspy committed Dec 25, 2018
1 parent b0f41b7 commit 0293e85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion components/checkbox/agree-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Output,
EventEmitter,
HostBinding,
ChangeDetectorRef,
ViewEncapsulation,
ChangeDetectionStrategy
} from '@angular/core';
Expand Down Expand Up @@ -54,7 +55,7 @@ export class AgreeItem implements ControlValueAccessor {
@HostBinding('class.am-checkbox-agree')
checkboxAgree: boolean = true;

constructor() { }
constructor(private cdr: ChangeDetectorRef) { }

change(event) {
this.checked = event.checked;
Expand All @@ -64,6 +65,7 @@ export class AgreeItem implements ControlValueAccessor {

writeValue(value: boolean): void {
this.checked = value;
this.cdr.markForCheck();
}

registerOnChange(fn: (_: boolean) => {}): void {
Expand Down
5 changes: 3 additions & 2 deletions components/checkbox/checkbox-item.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, forwardRef, Input, Output, EventEmitter, ChangeDetectionStrategy, ViewEncapsulation } from '@angular/core';
import { Component, forwardRef, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef, ViewEncapsulation } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

export interface CheckboxStatus {
Expand Down Expand Up @@ -41,7 +41,7 @@ export class CheckboxItem implements ControlValueAccessor {
@Output()
onChange = new EventEmitter<CheckboxStatus>();

constructor() { }
constructor(private cdr: ChangeDetectorRef) { }

onCheckboxClick(event) { }

Expand All @@ -53,6 +53,7 @@ export class CheckboxItem implements ControlValueAccessor {

writeValue(value: boolean): void {
this.checked = value;
this.cdr.markForCheck();
}

registerOnChange(fn: (_: boolean) => {}): void {
Expand Down
4 changes: 2 additions & 2 deletions components/checkbox/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ import { Component } from '@angular/core';
export class DemoCheckboxBasicComponent {
checkItemListData = [
{ value: 0, name: 'Ph.D.', checked: false },
{ value: 1, name: 'Bachelor', checked: false },
{ value: 1, name: 'Bachelor', checked: true },
{ value: 2, name: 'College diploma', checked: false }
];
disabledStatus: boolean = true;
disabledCheckboxItemStatus: boolean = true;
agreeItemData = { value: 'Agree Submit', name: 'Agree Item', checked: false };
agreeItemData = { value: 'Agree Submit', name: 'Agree Item', checked: true };

onChange = (val: any) => {
console.log('onChange Event: ', val);
Expand Down

0 comments on commit 0293e85

Please sign in to comment.