diff --git a/components/buttons/button-radio.directive.ts b/components/buttons/button-radio.directive.ts index bf7398741d..8db96adb02 100644 --- a/components/buttons/button-radio.directive.ts +++ b/components/buttons/button-radio.directive.ts @@ -3,13 +3,13 @@ import { } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; -/*tslint:disable*/ +/* tslint:disable */ export const RADIO_CONTROL_VALUE_ACCESSOR: any = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ButtonRadioDirective), multi: true }; -/*tslint:enable*/ +/* tslint:enable */ @Directive({ selector: '[btnRadio]', providers: [RADIO_CONTROL_VALUE_ACCESSOR] }) export class ButtonRadioDirective implements ControlValueAccessor, OnInit { diff --git a/components/utils/components-helper.service.ts b/components/utils/components-helper.service.ts index 744f8c24b8..3a8a65e41f 100644 --- a/components/utils/components-helper.service.ts +++ b/components/utils/components-helper.service.ts @@ -39,14 +39,20 @@ export class ComponentsHelper { * @returns {ViewContainerRef} - application root view component ref */ public getRootViewContainerRef():ViewContainerRef { - // The only way for now (by @mhevery) - // https://github.com/angular/angular/issues/6446#issuecomment-173459525 - const appInstance = this.applicationRef.components[0].instance; - if (!appInstance.viewContainerRef) { - const appName = this.applicationRef.componentTypes[0].name; - throw new Error(`Missing 'viewContainerRef' declaration in ${appName} constructor`); + // https://github.com/angular/angular/issues/9293 + const comps = this.applicationRef.components; + + if(!comps.length) { + throw new Error(`ApplicationRef instance not found`); + } + + try { + /* one more ugly hack, read issue above for details */ + const root = (this.applicationRef as any )._rootComponents[0]; + return root._hostElement.vcRef; + } catch (e) { + throw new Error(`ApplicationRef instance not found`); } - return appInstance.viewContainerRef; } /**