Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

angular - How to generate your classes in a specific folder with Angula2 CLI?

I usually generate classes with the angular 2 cli with the following command:

ng g class todo

How can I tell the cli to generate the classes in a particular folder, for example a models folder.

The documentation has an example where they generate a component in a specific folder but I've had no success with the class option

I've tried the following options:

ng g class models/todo

ng g class ../models todo

ng g class models todo

They result in either an error that the path is invalid, which makes me think that the option is supported but I can't figure it out or in the case of the latter merges the intended folder name with the class name.

question from:https://stackoverflow.com/questions/40241375/how-to-generate-your-classes-in-a-specific-folder-with-angula2-cli

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Generated items for the Angular CLI are relative...

if you are in the root dir (or the source dir) you are perceived to be in the app dir...

~/me/foo > ng g c bar
// ~/me/foo/src/app/bar/bar.component*

~/me/foo/src > ng g c bar
// ~/me/foo/src/app/bar/bar.component*

if you are in the app directory or further down the folder structure you will generate to where you are...

~/me/foo/src/app/feature > ng g c bar
// ~/me/foo/src/app/feature/bar/bar.component*

~/me/foo/src/app/feature > ng g c ../bar
// ~/me/foo/src/app/bar/bar.component*

Note: if you try to generate into a dir that does not exist, it will error...

~/me/foo/src/app > ng g c a/b/c/d/e/f/g/bar
// Error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...