Skip to content

Ng Generator does not save components in correct directory #6431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iamclaytonray opened this issue May 23, 2017 · 7 comments
Closed

Ng Generator does not save components in correct directory #6431

iamclaytonray opened this issue May 23, 2017 · 7 comments
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent severity3: broken

Comments

@iamclaytonray
Copy link

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.3
node: 7.10.0
os: darwin x64
@angular/common: 4.1.3
@angular/compiler: 4.1.3
@angular/core: 4.1.3
@angular/forms: 4.1.3
@angular/http: 4.1.3
@angular/platform-browser: 4.1.3
@angular/platform-browser-dynamic: 4.1.3
@angular/router: 4.1.3
@angular/cli: 1.0.3
@angular/compiler-cli: 4.1.3

Repro steps.

ng new my-app
cd my-app/src/app && mkdir components
cd components
ng g component posts

Those are the only steps I took. I didn't touch the code. I just ran those commands. However, the posts component did not save under the components directory. They were saved in the app directory, even though I was in the components directory when running the generator. I am pretty new to Angular (first day) so I am not sure if that is the expected result or not. I wouldn't imagine that being the case, though.

The log given by the failure.

No logs.

Desired functionality.

The answer is for both questions. When you are in a specific directory and run ng g component component-name, the generated files should be a child of your current directory via the command line.

Mention any other details that might be useful.

Here's a screenshot of the file structure.
screen shot 2017-05-23 at 7 56 55 pm

@Brocco Brocco added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent severity3: broken labels May 24, 2017
@sumitarora
Copy link
Contributor

@iamclaytonray ng command runs relative to you project location. To generate components to a specific folder you can just do ng g c components/hello which will generate hello component in src\app\components folder.

@iamclaytonray
Copy link
Author

Ahh, okay. That worked for me. Maybe that could be a future feature? It seems like it would be more logical to be absolute over relative.

@sumitarora
Copy link
Contributor

@iamclaytonray It is the default behavior as all other commands run based on root ng s, ng b, ng test etc. no matter where in the project path you are.

@chriscurnow
Copy link

@sumitarora I don't accept the behaviour you describe is the default behaviour and if it was the default behaviour, it should not be.

I have been using angular cli since somewhere in the beta program. It has never worked this way. CLI always generates the object (component, service, module etc) in the current directory.

It is would be an absolute pain having to write out the path in full every time. Take an example from my current project, to create a new component in the supplier-create directory, given your approach I would have to write

ng g c contract/subcontract/subcontract-edit/subcontract-new/supplier-select/supplier-create/new-component-name.

We have NEVER had to do this.

I have always been able to navigate to the directory (in this case `supplier-create') and type

ng g c new-component-name

I just tried the exact steps described by @iamclaytonray and the result was

create src/app/components/posts/posts.component.css
  create src/app/components/posts/posts.component.html
  create src/app/components/posts/posts.component.spec.ts
  create src/app/components/posts/posts.component.ts
  update src/app/app.module.ts

Which is exactly what I would expect and indeed hope for.

@iamclaytonray I hope you have worked out by now that you can indeed to what you expected to do. If not, there is something wrong somewhere.

@iamclaytonray
Copy link
Author

I didn't think or expect that to be the behavior, especially for Google's codebase but I just dealt with it. Honestly, I didn't entertain Angular after that and moved to React. I could test it out again and see what the results are, if you'd like?

@chriscurnow
Copy link

@iamclaytonray - no problems. No need to test it out. I'm quite happy it works. I just didn't want others coming to this answer and think Angular was harder than it was.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent severity3: broken
Projects
None yet
Development

No branches or pull requests

4 participants