2

I want to be able to create components or modules or services in folder external to /src/app/...

so i've tried with ng g c ../mco/lib but it fail.

I want to be able to create with the CLI a component in folder external to app.

how can i achieve this ?

EDIT

You can change the appRoot of AngularCli, so in angular-cli.json i've added in "apps" array, a property "appRoot": "mco"

4 Answers 4

6

You can just define the right path and the angular-cli will get everything ready for you, for example if you want the component to be build outside app folder on a example folder you can try ng g c ../example/yourComponent

Sign up to request clarification or add additional context in comments.

1 Comment

This should be the accepted answer as it does not require modifying angular-cli.json
3

For those who finds appRoot is not working on @angular/cli 6. Here is a workaround:

{
"projects": {
"my-project": {
  "root": "/path/to/project",
  "projectType": "application",
  "schematics": {
      "@schematics/angular:component": {
        "path": "/path/to/project"
      },
      "@schematics/angular:directive": {
        "path": "/path/to/project"
      },
      "@schematics/angular:module": {
        "path": "/path/to/project"
      },
      "@schematics/angular:service":{
        "path": "/path/to/project"
      },
      "@schematics/angular:pipe": {
        "path": "/path/to/project"
      },
      "@schematics/angular:class": {
        "path": "/path/to/project"
      }
  }
}
}

Now you can run

ng g component hello-world --project=my-project --dry-run

to check if the hello-world is output to /path/to/project/hello-world.

Comments

2

Change the appRoot of AngularCli.

So in angular-cli.json

  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "tr",
      "appRoot": "mco"
    }
  ],

Comments

0

I'm not sure if this feature exists in Angular CLI. Assuming you are in src/app directory you can just create component in default location and then move it to desired place like this:

ng g c my-component; mv my-component /Users/username/desiredlocation/

3 Comments

i found the way to do it ;) i will edit my post to show how i did it
Nice :) You can also write answer to your own question.
Clearly, this is not what the op wants. Also, this prevents IDEs like VSCode to do refactoring changes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.