Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular应用程序在发生更改时不会刷新内容,即使重新生成_Angular_Asp.net Core_Asp.net Web Api - Fatal编程技术网

Angular应用程序在发生更改时不会刷新内容,即使重新生成

Angular应用程序在发生更改时不会刷新内容,即使重新生成,angular,asp.net-core,asp.net-web-api,Angular,Asp.net Core,Asp.net Web Api,我已经开始了一个以ASP.Net核心Web API作为后端的项目,前端是Angular应用程序。然而,我决定自己动手做,而不是使用SPA的默认模板。所以我创建了一个空白的ASP.NET核心项目,然后使用Angular CLI添加了Angular项目。实际上,我在Angular项目配置中唯一更改的是Angular.json中的outputPath-我将其更改为../wwwroot 然后我在Startup类中设置了.Net应用程序中的所有内容 我使用ngserve启动angular,然后使用Visu

我已经开始了一个以ASP.Net核心Web API作为后端的项目,前端是Angular应用程序。然而,我决定自己动手做,而不是使用SPA的默认模板。所以我创建了一个空白的ASP.NET核心项目,然后使用Angular CLI添加了Angular项目。实际上,我在Angular项目配置中唯一更改的是Angular.json中的outputPath-我将其更改为../wwwroot

然后我在Startup类中设置了.Net应用程序中的所有内容

我使用
ngserve
启动angular,然后使用VisualStudio构建.net项目。但是,Angular应用程序在检测到其中一个文件中的更改时,不会刷新/更改内容。有趣的是,它进行了一些重建,但新内容不会出现,除非我停止应用程序,运行
ng build
,然后用
ng service
再次启动它。我相信我在两个项目中都把配置搞砸了,所以如果有任何帮助,我将不胜感激。我在下面提供了一些代码

这是我的Startup类(我已经隐藏了所有与DI或授权设置相关的内容,因为我发现它们不相关)

这是我的angular.json


    {
        "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
        "version": 1,
        "newProjectRoot": "projects",
        "projects": {
            "client-app": {
                "projectType": "application",
                "schematics": {},
                "root": "",
                "sourceRoot": "src",
                "prefix": "app",
                "architect": {
                    "build": {
                        "builder": "@angular-devkit/build-angular:browser",
                        "options": {
                            "outputPath": "../wwwroot",
                            "index": "src/index.html",
                            "main": "src/main.ts",
                            "polyfills": "src/polyfills.ts",
                            "tsConfig": "tsconfig.app.json",
                            "aot": false,
                            "assets": [
                                "src/favicon.ico",
                                "src/assets"
                            ],
                            "styles": [
                                "src/styles.css"
                            ],
                            "scripts": []
                        },
                        "configurations": {
                            "production": {
                                "fileReplacements": [
                                    {
                                        "replace": "src/environments/environment.ts",
                                        "with": "src/environments/environment.prod.ts"
                                    }
                                ],
                                "optimization": true,
                                "outputHashing": "all",
                                "sourceMap": false,
                                "extractCss": true,
                                "namedChunks": false,
                                "aot": true,
                                "extractLicenses": true,
                                "vendorChunk": false,
                                "buildOptimizer": true,
                                "budgets": [
                                    {
                                        "type": "initial",
                                        "maximumWarning": "2mb",
                                        "maximumError": "5mb"
                                    },
                                    {
                                        "type": "anyComponentStyle",
                                        "maximumWarning": "6kb",
                                        "maximumError": "10kb"
                                    }
                                ]
                            }
                        }
                    },
                    "serve": {
                        "builder": "@angular-devkit/build-angular:dev-server",
                        "options": {
                            "browserTarget": "client-app:build"
                        },
                        "configurations": {
                            "production": {
                                "browserTarget": "client-app:build:production"
                            }
                        }
                    },
                    "extract-i18n": {
                        "builder": "@angular-devkit/build-angular:extract-i18n",
                        "options": {
                            "browserTarget": "client-app:build"
                        }
                    },
                    "test": {
                        "builder": "@angular-devkit/build-angular:karma",
                        "options": {
                            "main": "src/test.ts",
                            "polyfills": "src/polyfills.ts",
                            "tsConfig": "tsconfig.spec.json",
                            "karmaConfig": "karma.conf.js",
                            "assets": [
                                "src/favicon.ico",
                                "src/assets"
                            ],
                            "styles": [
                                "src/styles.css"
                            ],
                            "scripts": []
                        }
                    },
                    "lint": {
                        "builder": "@angular-devkit/build-angular:tslint",
                        "options": {
                            "tsConfig": [
                                "tsconfig.app.json",
                                "tsconfig.spec.json",
                                "e2e/tsconfig.json"
                            ],
                            "exclude": [
                                "**/node_modules/**"
                            ]
                        }
                    },
                    "e2e": {
                        "builder": "@angular-devkit/build-angular:protractor",
                        "options": {
                            "protractorConfig": "e2e/protractor.conf.js",
                            "devServerTarget": "client-app:serve"
                        },
                        "configurations": {
                            "production": {
                                "devServerTarget": "client-app:serve:production"
                            }
                        }
                    }
                }
            }
        },
        "defaultProject": "client-app"
    }


由于您使用的是不同的服务器,而不是包含的webpack dev服务器,因此需要构建输出并将其放入您自己的服务器wwwroot中。这可能很乏味,但最好的选择是在开发过程中在构建中使用is
--watch
标记

为您当地的发展尝试一下

ng build --watch
回答:不适用于VS2019和角度v9+


您告诉Angular在wwwroot中输出构建,但当您提供服务时,它实际上有自己的服务器和位置。因此,为了不在每次更改中重建,我应该怎么做?我也想为后端自动化这个过程,但我听说过dotnet watch,希望安装它不会导致任何重大问题构建——watchIt成功了,谢谢。现在我想知道所有这些是如何在Visual Studio模板中设置的,因此您不必担心所有这些内容。在package.json替换脚本中,从
ng serve
开始到
ng build--watch
开始使用
npm start
很好的速记。顺便说一句,是否可以使用当前配置启用热模块替换?VS2019和angular 9不起作用…页面不再刷新我不再使用ASP.net。我已将答案标记为过时。你可以在这个问题上悬赏以吸引答案或提出新问题。对不起:(
ng build --watch