2

I've found plenty about how to setup my schematic file to skip certain things (like the spec file) when creating a component using ng generate but what I can't find anywhere is how to not include the implements OnInit when I use ng generate component.

I've looked everwhere. Anyone have an idea?

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Brad
  • 722
  • 2
  • 8
  • 24

2 Answers2

2

As of today, there is no option for this yet.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
0

There is no official way to do this, but there is a trick that allows you to generate new components without implements OnInit or Constructor().

You just have to mismatch the node version. The Constructorand implements OnInit is not generated when using node 16.17.0 with Angular v15 in Windows, but it works fine in Linux Ubuntu. So you'll have to figure it out for yourself by changing only the minor version of the node. 

  • 3
    This is interesting trivia, but sounds more like a bug. And possibly a bug only with those specific versions. I don't think this is something that should be relied on. – Brad Jan 22 '23 at 18:41
  • Yes, I also think that is more like a bug, but in recent days I have encountered this many times, and after searching on the internet, I didn't find any answers that helped me solve this. So if any person encounters that issue like I did and doesn't know what to do, they will get the idea from that answer. – Atharva Kavale Jan 30 '23 at 10:03