66
77<# var implementedInterfaces = [' OnDestroy' ]; #>
88
9- <# it.isEditor && implementedInterfaces.push(' OnInit' ) && implementedInterfaces.push(' AfterViewInit' ); #>
109<# it.isEditor && implementedInterfaces.push(' ControlValueAccessor' ); #>
1110<# collectionProperties.length && implementedInterfaces.push(' OnChanges' , ' DoCheck' ); #>
1211
@@ -23,11 +22,11 @@ import {
2322
2423 Input,
2524 Output,
26- OnDestroy,
25+ OnDestroy,<#? it.isExtension #>
26+ SkipSelf,
27+ Optional,
28+ Host,<#?#>
2729 EventEmitter<#? it.isEditor #>,
28- OnInit,
29- AfterViewInit,
30- ContentChild,
3130 forwardRef,
3231 HostListener<#?#><#? collectionProperties.length #>,
3332 OnChanges,
@@ -42,8 +41,6 @@ import DevExpress from 'devextreme/bundles/dx.all';<#?#>
4241
4342import <#= it.className #> from ' <#= it.module #>' ;
4443<#? it.isEditor #>
45- import { DxValidatorComponent } from ' ./validator' ;
46-
4744import {
4845 ControlValueAccessor,
4946 NG_VALUE_ACCESSOR
@@ -87,10 +84,6 @@ const CUSTOM_VALUE_ACCESSOR_PROVIDER = {
8784})
8885export class <#= it.className #>Component extends <#= baseClass #> <#? implementedInterfaces.length #>implements <#= implementedInterfaces.join(' , ' ) #> <#?#>{
8986 instance: <#= it.className #>;
90- <#? it.isEditor #>
91- @ContentChild(DxValidatorComponent)
92- validator: DxValidatorComponent;
93- <#?#>
9487<#~ it.properties :prop:i #><#? prop.description #>
9588 /**
9689 * <#= prop.description #>
@@ -125,9 +118,15 @@ export class <#= it.className #>Component extends <#= baseClass #> <#? implement
125118 }
126119<#~#>
127120
121+ <#? it.isExtension #>
122+ parentElement: any;
123+ <#?#>
124+
128125 constructor(elementRef: ElementRef, ngZone: NgZone, templateHost: DxTemplateHost,
129126 <#? collectionProperties.length #>private <#?#>_watcherHelper: WatcherHelper<#? collectionProperties.length #>,
130- private _idh: IterableDifferHelper<#?#>, optionHost: NestedOptionHost,
127+ private _idh: IterableDifferHelper<#?#>,<#? it.isExtension #>
128+ @SkipSelf() @Optional() @Host() parentOptionHost: NestedOptionHost,<#?#>
129+ optionHost: NestedOptionHost,
131130 transferState: TransferState,
132131 @Inject(PLATFORM_ID) platformId: any) {
133132
@@ -136,15 +135,30 @@ export class <#= it.className #>Component extends <#= baseClass #> <#? implement
136135 this._createEventEmitters([
137136 <#~ it.events :event:i #>{ <#? event.subscribe #>subscribe: ' <#= event.subscribe #>' , <#?#>emit: ' <#= event.emit #>' }<#? i < it.events.length-1 #>,
138137 <#?#><#~#>
139- ]);<#? collectionProperties.length #>
138+ ]);<#? it.isExtension #>
139+ this.parentElement = this.getParentElement(parentOptionHost);<#?#><#? collectionProperties.length #>
140140
141141 this._idh.setHost(this);<#?#>
142142 optionHost.setHost(this);
143143 }
144144
145145 protected _createInstance(element, options) {
146+ <#? it.isExtension #>
147+ if (this.parentElement) {
148+ return new DxValidator(this.parentElement, options);
149+ }
150+ <#?#>
146151 return new <#= it.className #>(element, options);
147152 }
153+ <#? it.isExtension #>
154+ private getParentElement(host) {
155+ if (host) {
156+ const parentHost = host.getHost();
157+ return (parentHost as any).element.nativeElement;
158+ }
159+ return ;
160+ }
161+ <#?#>
148162<#? it.isEditor #>
149163 writeValue(value: any): void {
150164 this.eventHelper.lockedValueChangeEvent = true;
@@ -196,19 +210,6 @@ export class <#= it.className #>Component extends <#= baseClass #> <#? implement
196210 super._setOption(name, value);
197211 }
198212 }<#?#>
199- <#? it.isEditor #>
200- ngOnInit() {
201- super.ngOnInit();
202- if (this.validator) {
203- this.validator.createInstanceOnInit = false;
204- }
205- }
206- ngAfterViewInit() {
207- super.ngAfterViewInit();
208- if (this.validator) {
209- this.validator.createInstance(this.element.nativeElement);
210- }
211- }<#?#>
212213}
213214
214215@NgModule({
0 commit comments