简体   繁体   中英

Cannot create angular component in Visual Studio Code

I am trying to create an angular component in visual studio code. By default, my angular components are in ClientApp. I have some default components in ClientApp. When I tried to add a new angular component in the components folder in ClientApp I get an error.

When I enter "ng g component vehicle-form" I have an error. It says " Invalid path: "vehicle-form" cannot be above the "ClientApp\\app" directory." However, my angular components are in the app folder located within the app folder of Client App.

PS C:\\Users\\Sushi\\vega> cd ClientApp
PS C:\\Users\\Sushi\\vega\\ClientApp> cd app
PS C:\\Users\\Sushi\\vega\\ClientApp\\app> cd components
PS C:\\Users\\Sushi\\vega\\ClientApp\\app\\components> ng g component vehicle-form
Invalid path: "vehicle-form" cannot be above the "ClientApp\\app" directory

My .angular-cli.json configuration is as listed below.

"apps": [
        {
          "root": "ClientApp",
          "outDir": "dist",
          "assets": [
            "assets",
            "favicon.ico"

If you want to create a component from angular cli then just run the command

  ng g component vehicle-form

From your root directory ie

 PS C:\Users\Sushi\vega\ClientApp> ng g component vehicle-form

try to change

 "apps": [
        {
          "root": "src",
          "outDir": "dist",
          "assets": [
            "assets",
            "favicon.ico"

then ng gc vehicle-form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM