php 如何在 xampp 服务器上运行 Angular 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44640670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:00:54  来源:igfitidea点击:

How to run Angular app on xampp server?

phpangularxampp

提问by Ahmer Ali Ahsan

I'm working with Angular 2 with php. Before I started PHP with Angular 2. I have done Angular 2 with node.js on server localhost:3000. Now with PHP, how I can configure my Angular 2 app with xampp server so my server code is running on localhost:8080. Please help me on this.

我正在使用带有 php 的 Angular 2。在我使用 Angular 2 开始 PHP 之前。我已经在服务器 localhost:3000 上使用 node.js 完成了 Angular 2。现在使用 PHP,如何使用 xampp 服务器配置我的 Angular 2 应用程序,以便我的服务器代码在 localhost:8080 上运行。请帮我解决这个问题。

回答by Ahmer Ali Ahsan

Here is my answer.

这是我的答案。

You can write Angular2 app just using Angular2 packages without using node or mamp or xampp and host that app. Ref

您可以仅使用 Angular2 包编写 Angular2 应用程序,而无需使用 node 或 mamp 或 xampp 并托管该应用程序。参考

According to the above reference I created my app using angular 2 - cli after that I made a little change in my root directory index.html file which is:

根据上面的参考,我使用 angular 2 - cli 创建了我的应用程序,之后我在我的根目录 index.html 文件中做了一些改动,它是:

<base href="/">

into

进入

<base href="./">

and build my app using:

并使用以下方法构建我的应用程序:

ng build --prod

copy dist folder and paste it in my xampp htdocs folder and access the site using:

复制 dist 文件夹并将其粘贴到我的 xampp htdocs 文件夹中,然后使用以下命令访问该站点:

localhost:8080/dist/

本地主机:8080/dist/

output

输出

App works

应用程序有效

回答by Josh Dando

You can host it on any server by first building the angular project using the command line:

您可以通过首先使用命令行构建 angular 项目将其托管在任何服务器上:

ng build --base-href "/football/" --prod

This base href will mean that it expects the final server to be something like: localhost:8080/football/.

这个基本的 href 意味着它期望最终的服务器是这样的:localhost:8080/football/。

You want to get everything that is made in the dist folder and paste it into your server inside a folder called football.

您想要获取在 dist 文件夹中制作的所有内容并将其粘贴到名为 Football 的文件夹内的服务器中。

回答by Mario Medrano Medrano

I think that you are looking something similar to:

我认为您正在寻找类似于以下内容的内容:

angular-cli server - how to proxy API requests to another server?

angular-cli 服务器 - 如何将 API 请求代理到另一台服务器?

Just run your angular 2 application using the CLI, and add the proxy to use the services that are in xampp.

只需使用 CLI 运行您的 angular 2 应用程序,并添加代理以使用 xampp 中的服务。