@@ -26,7 +26,8 @@ function getComponents(excludeComponents: string[], cmpRegistry: d.ComponentRegi
2626
2727async function angularDirectiveProxyOutput ( config : d . Config , compilerCtx : d . CompilerCtx , outputTarget : d . OutputTargetAngular , cmpRegistry : d . ComponentRegistry ) {
2828 const components = getComponents ( outputTarget . excludeComponents , cmpRegistry ) ;
29- const { hasDirectives, hasOutputs, proxies } = generateProxies ( components ) ;
29+ const useDirectives = outputTarget . useDirectives ;
30+ const { hasOutputs, proxies } = generateProxies ( components , useDirectives ) ;
3031
3132 const auxFunctions : string [ ] = [
3233 inputsAuxFunction ( ) ,
@@ -37,10 +38,15 @@ async function angularDirectiveProxyOutput(config: d.Config, compilerCtx: d.Comp
3738 'ElementRef'
3839 ] ;
3940
40- if ( hasDirectives ) {
41- angularImports . push ( 'Component' ) ;
42- angularImports . push ( 'ViewEncapsulation' ) ;
43- angularImports . push ( 'ChangeDetectionStrategy' ) ;
41+ if ( components . length > 0 ) {
42+ if ( useDirectives ) {
43+ angularImports . push ( 'Directive' ) ;
44+ } else {
45+ angularImports . push ( 'Component' ) ;
46+ angularImports . push ( 'ViewEncapsulation' ) ;
47+ angularImports . push ( 'ChangeDetectionStrategy' ) ;
48+ angularImports . push ( 'ChangeDetectorRef' ) ;
49+ }
4450 }
4551
4652 if ( hasOutputs ) {
@@ -111,15 +117,13 @@ export function proxyMethods(instance: any, el: any, methods: string[]) {
111117` ;
112118}
113119
114- function generateProxies ( components : d . ComponentMeta [ ] ) {
115- let hasDirectives = false ;
120+ function generateProxies ( components : d . ComponentMeta [ ] , useDirectives : boolean ) {
116121 let hasMethods = false ;
117122 let hasOutputs = false ;
118123 let hasInputs = false ;
119124
120125 const lines = components . map ( cmpMeta => {
121- const proxy = generateProxy ( cmpMeta ) ;
122- hasDirectives = true ;
126+ const proxy = generateProxy ( cmpMeta , useDirectives ) ;
123127 if ( proxy . hasInputs ) {
124128 hasInputs = true ;
125129 }
@@ -134,14 +138,13 @@ function generateProxies(components: d.ComponentMeta[]) {
134138
135139 return {
136140 proxies : lines . join ( '\n' ) ,
137- hasDirectives,
138141 hasInputs,
139142 hasMethods,
140143 hasOutputs
141144 } ;
142145}
143146
144- function generateProxy ( cmpMeta : d . ComponentMeta ) {
147+ function generateProxy ( cmpMeta : d . ComponentMeta , useDirectives : boolean ) {
145148 // Collect component meta
146149 const inputs = getInputs ( cmpMeta ) ;
147150 const outputs = getOutputs ( cmpMeta ) ;
@@ -154,20 +157,25 @@ function generateProxy(cmpMeta: d.ComponentMeta) {
154157 const hasContructor = hasInputs || hasOutputs || hasMethods ;
155158
156159 // Generate Angular @Directive
160+ const decorator = useDirectives ? 'Directive' : 'Component' ;
157161 const directiveOpts = [
158162 `selector: \'${ cmpMeta . tagNameMeta } \'` ,
159- `changeDetection: ChangeDetectionStrategy.OnPush` ,
160- `encapsulation: ViewEncapsulation.None` ,
161- `template: '<ng-content></ng-content>'`
162163 ] ;
164+ if ( ! useDirectives ) {
165+ directiveOpts . push (
166+ `changeDetection: ChangeDetectionStrategy.OnPush` ,
167+ `encapsulation: ViewEncapsulation.None` ,
168+ `template: '<ng-content></ng-content>'`
169+ ) ;
170+ }
163171 if ( inputs . length > 0 ) {
164172 directiveOpts . push ( `inputs: ['${ inputs . join ( `', '` ) } ']` ) ;
165173 }
166174
167175 const tagNameAsPascal = dashToPascalCase ( cmpMeta . tagNameMeta ) ;
168176 const lines = [ `
169177export declare interface ${ cmpMeta . componentClass } extends StencilComponents<'${ tagNameAsPascal } '> {}
170- @Component ({ ${ directiveOpts . join ( ', ' ) } })
178+ @${ decorator } ({ ${ directiveOpts . join ( ', ' ) } })
171179export class ${ cmpMeta . componentClass } {` ] ;
172180
173181 // Generate outputs
@@ -177,9 +185,16 @@ export class ${cmpMeta.componentClass} {`];
177185
178186 // Generate component constructor
179187 if ( hasContructor ) {
180- lines . push ( `
188+ if ( useDirectives ) {
189+ lines . push ( `
181190 constructor(r: ElementRef) {
182191 const el = r.nativeElement;` ) ;
192+ } else {
193+ lines . push ( `
194+ constructor(c: ChangeDetectorRef, r: ElementRef) {
195+ c.detach();
196+ const el = r.nativeElement;` ) ;
197+ }
183198 }
184199
185200 if ( hasMethods ) {
0 commit comments