1- import { Component , OnInit , Input , forwardRef , Output , EventEmitter } from '@angular/core' ;
1+ import { Component , OnInit , Input , forwardRef , Output , EventEmitter , OnChanges , SimpleChanges } from '@angular/core' ;
22import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
33import { NgToggleConfig } from './ng-toggle.config' ;
44
@@ -22,7 +22,7 @@ const DISABLED_BUTTON_COLOR = 'silver'
2222 }
2323 ]
2424} )
25- export class NgToggleComponent implements OnInit , ControlValueAccessor {
25+ export class NgToggleComponent implements OnInit , ControlValueAccessor , OnChanges {
2626
2727 @Input ( ) value : any = this . config . value || true
2828 @Input ( ) name : string = this . config . name || ''
@@ -57,6 +57,7 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor {
5757
5858 onInput ( value : boolean ) {
5959 this . value = value ;
60+ console . log ( this . value , value , 'calue' )
6061 this . onTouch ( ) ;
6162 this . onChange ( this . value ) ;
6263 }
@@ -82,6 +83,14 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor {
8283 this . toggled = Object . keys ( this . values ) [ index ] == 'checked' ? true : false
8384 }
8485
86+ ngOnChanges ( changes : SimpleChanges ) {
87+ for ( const propName in changes ) {
88+ const chng = changes [ propName ] ;
89+ if ( propName == 'value' )
90+ this . writeValue ( chng . currentValue )
91+ }
92+ }
93+
8594 get coreStyle ( ) {
8695 return {
8796 width : px ( this . width ) ,
0 commit comments