Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to generate one ts file Rather than four file during generate component in angular17?

It’s any way to create component with cli to select the files of generate component? Or it can only set in the template in editors.

Sometimes, I need to create a simple component and i want to create a standalone component with one ts file,
However, when i use ng g c --standalone AComponent, It will create html, scss, spec, ts four file;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In the angular.json, we can also configure it in @schematics/angular:component.

...
"schematics": {
  "@schematics/angular:component": {
       "prefix": "app",
       "style": "scss",
       "skipTests": true,
       "inlineStyle": true,
       "inlineTemplate": true,
  },
  ...

We can also use the arguments to control this.

ng g c test -s -t --skip-tests

ng generate component

–inline-style

Alias: s
Include styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the > component.ts file.
Value Type: boolean
Default: false


–inline-template

Alias: t
Include template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file.
Value Type: boolean
Default: false


–skip-selector

Specifies if the component should have a selector or not.
Value Type: boolean
Default: false


–skip-tests

Do not create "spec.ts" test files for the new component.
Value Type: boolean
Default: false

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading