question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ng Generator does not save components in correct directory

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
chriscurnowcommented, Aug 11, 2017

@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.

1reaction
chriscurnowcommented, Aug 12, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ng Generator does not always save components in correct ...
I cd to a module directory in my project eg: app/admin. I create a new component, eg ng g c users. Instead of...
Read more >
Angular CLI generate component issue - Stack Overflow
I smell ng finds multiple module files on app root, please supply module while generating component ng generate component componentName ...
Read more >
ng generate component using the CLI - Pluralsight
ng generate component is a simple one-line command which creates different files and a folder, and it references the newly created component ......
Read more >
ng generate - Angular
This command has the following sub-commands: app-shell · application · class · component · directive · enum · guard · interceptor · interface...
Read more >
Exporting an Excel file in Angular | by Madhava Kumar Ippili
Today I will show you the way to export a xlsx file from angular6. ... With in this directory generate a service file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found