angular-ct icon indicating copy to clipboard operation
angular-ct copied to clipboard

Add Support for StandAlone Components

Open jordanpowell88 opened this issue 3 years ago • 2 comments

With StandAlone Components getting released as part of Angular 14 we need to validate that they work as is and see if any changes would be important to make this more ergonomic

jordanpowell88 avatar May 20 '22 14:05 jordanpowell88

👋 hey @jordanpowell88 !

I had an issue with jitMode (that'ill describe in another issue) so I had to try standalones to see if it's a module resolution issue.

IMO, there isn't much to do for it to work. Actually, there is less to do than with modules 😄.

The mount function should detect if it's a standalone or not. This can be done like this

const { standalone } = component['__annotations__'].find(annotation => annotation.__proto__.ngMetadataName === 'Component')

const testBedConfiguration = standalone ? { imports: [component] } : { declarations: [component] };

Angular has some internal helpers for grabbing the meta but they are not publicly exposed ☹️ Cf. https://github.com/angular/angular/blob/d4f11147f452c236cb039511f1a509dd5de1eb51/packages/core/src/render3/jit/module.ts#L390

Also, when using a standalone, if the user sets imports, we have to override the imports using TestBed.overrideComponent. We have to figure out a convenient API to allow settings/adding/removing just like overrideComponent.

yjaaidi avatar Jun 13 '22 00:06 yjaaidi

Actually, it's better to detect if the component is standalone using (AppComponent as any).ɵcmp.standalone. We should note that Angular might expose a public function to properly detect if the component is a standalone.

yjaaidi avatar Jun 14 '22 17:06 yjaaidi