Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@Directive({
selector: '[mdcRadio]'
})
export class MdcRadioDirective extends AbstractMdcRipple implements AfterContentInit, OnDestroy {
@HostBinding('class.mdc-radio') _cls = true;
@ContentChild(MdcRadioInputDirective) _input: MdcRadioInputDirective;
private mdcAdapter: MdcRadioAdapter = {
addClass: (className: string) => {
this.renderer.addClass(this.root.nativeElement, className);
},
removeClass: (className: string) => {
this.renderer.removeClass(this.root.nativeElement, className);
},
getNativeControl: () => this._input ? this._input._elm.nativeElement : null
};
private foundation: { init: Function, destroy: Function } = new MDCRadioFoundation(this.mdcAdapter);
constructor(private renderer: Renderer2, private root: ElementRef, private registry: MdcEventRegistry) {
super(root, renderer, registry);
}
ngAfterContentInit() {
this.addBackground();
this.initRipple();
this.foundation.init();
}
ngOnDestroy() {
this.destroyRipple();
this.foundation.destroy();
}
getDefaultFoundation() {
return new MDCRadioFoundation({
addClass: (className: string) => this.root.addClass(className),
removeClass: (className: string) => this.root.removeClass(className)
});
}
getDefaultFoundation() {
const adapter: MDCRadioAdapter = {
addClass: (className: string) => this._getHostElement().classList.add(className),
removeClass: (className: string) => this._getHostElement().classList.remove(className),
setNativeControlDisabled: (disabled: boolean) => this.disabled = disabled
};
return new MDCRadioFoundation(adapter);
}
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MatRadioButton implements AfterViewInit, OnDestroy {
private _uniqueId: string = `mat-radio-${++nextUniqueId}`;
private _radioAdapter: MDCRadioAdapter = {
addClass: (className: string) => this._setClass(className, true),
removeClass: (className: string) => this._setClass(className, false),
setNativeControlDisabled: (disabled: boolean) => {
this._disabled = disabled;
this._changeDetectorRef.markForCheck();
},
};
_radioFoundation = new MDCRadioFoundation(this._radioAdapter);
_classes: {[key: string]: boolean} = {};
/** The unique ID for the radio button. */
@Input() id: string = this._uniqueId;
/** Whether the radio button is disabled. */
@Input()
get disabled(): boolean {
return this._disabled;
}
set disabled(disabled: boolean) {
this._radioFoundation.setDisabled(coerceBooleanProperty(disabled));
}
private _disabled = false;
constructor(private _changeDetectorRef: ChangeDetectorRef) {}