1

I'm new to Angular and now I want to create only a .ts file and not a whole component, can you please tell me how can I do it with ng generate?

Use-Case : While building the application I want to write the build version to a .ts.I want to load this file when this build is deployed and display the build version to user.

snow white
  • 61
  • 1
  • 2
  • 6

3 Answers3

9

Based on angular documents, you should specify exactly what your file is. It could be a function, class, interface, service, component, etc. For example, just create a file named letters.function.ts like this:

export function letters (){
   // do something
}

To facilitate creating more complicated stuff like components or services, it is recommended to use angular cli. For instance:

ng generate component letters
ng generate service letters
ng generate interface letters
ng generate class letters
5

you can create class using angular cli with ng g class className

behroozbc
  • 1,992
  • 2
  • 12
  • 25
0

What I think you mean by this is you want somewhere to put common functions, so in that case you would create a service. The ng generate command in that case is ng generate service. You can then inject the service into the components where you need it.

user2846469
  • 2,072
  • 3
  • 18
  • 32