在Angular项目的angular.json文件中,找到"options"下的"serving"属性,在属性值中加入"host"和"port",然后将Angular应用程序部署到指定的主机和端口。例如:
"options": {
"outputPath": "dist/my-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": [],
"allowedCommonJsDependencies": [],
"webWorkerTsConfig": "src/tsconfig.worker.json",
"aot": true,
"buildOptimizer": false,
"optimization": true,
"sourceMap": true,
"namedChunks": false,
"outputHashing": "none",
"statsJson": false,
"watch": false,
"serve": {
"host": "0.0.0.0",
"port": 4200
}
}
这样就可以在网络中访问您的Angular应用程序。您还需要确保您的服务器已配置正确,并已从Internet上可访问。