@@ -470,7 +470,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
470470
471471 this . mutationObserver = this . setMutationsObserver ( ) ;
472472
473- this . mutationObserver . observe ( this . _el . nativeElement , this . observerConfig ) ;
473+ this . mutationObserver ? .observe ( this . _el . nativeElement , this . observerConfig ) ;
474474 }
475475
476476 /**
@@ -483,7 +483,7 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
483483 this . queryListNotifier$ . next ( ) ;
484484 this . queryListNotifier$ . complete ( ) ;
485485
486- this . mutationObserver . disconnect ( ) ;
486+ this . mutationObserver ? .disconnect ( ) ;
487487 }
488488
489489 /**
@@ -513,28 +513,35 @@ export class IgxButtonGroupComponent extends DisplayDensityBase implements After
513513 }
514514 }
515515
516- this . mutationObserver . observe ( this . _el . nativeElement , this . observerConfig ) ;
516+ this . mutationObserver ? .observe ( this . _el . nativeElement , this . observerConfig ) ;
517517 }
518518
519519 private setMutationsObserver ( ) {
520- return new MutationObserver ( ( records , observer ) => {
521- // Stop observing while handling changes
522- observer . disconnect ( ) ;
520+ if ( typeof MutationObserver !== 'undefined' ) {
521+ return new MutationObserver ( ( records , observer ) => {
522+ // Stop observing while handling changes
523+ observer . disconnect ( ) ;
523524
524- const updatedButtons = this . getUpdatedButtons ( records ) ;
525+ const updatedButtons = this . getUpdatedButtons ( records ) ;
525526
526- if ( updatedButtons . length > 0 ) {
527- updatedButtons . forEach ( ( button ) => {
528- const index = this . buttons . map ( ( b ) => b . nativeElement ) . indexOf ( button ) ;
529- const args : IButtonGroupEventArgs = { owner : this , button : this . buttons [ index ] , index } ;
527+ if ( updatedButtons . length > 0 ) {
528+ updatedButtons . forEach ( ( button ) => {
529+ const index = this . buttons . map ( ( b ) => b . nativeElement ) . indexOf ( button ) ;
530+ const args : IButtonGroupEventArgs = { owner : this , button : this . buttons [ index ] , index } ;
530531
531- this . updateButtonSelectionState ( index , args ) ;
532- } ) ;
533- }
532+ this . updateButtonSelectionState ( index , args ) ;
533+ } ) ;
534+ }
534535
535- // Watch for changes again
536- observer . observe ( this . _el . nativeElement , this . observerConfig ) ;
537- } ) ;
536+ // Watch for changes again
537+ observer . observe ( this . _el . nativeElement , this . observerConfig ) ;
538+
539+ // Cleanup function
540+ this . _renderer . listen ( this . _el . nativeElement , 'DOMNodeRemoved' , ( ) => {
541+ observer . disconnect ( ) ;
542+ } ) ;
543+ } ) ;
544+ }
538545 }
539546
540547 private getUpdatedButtons ( records : MutationRecord [ ] ) {
0 commit comments