如何在PHP应用程序中使用Angular 2? [英] How can I use Angular 2 in PHP application?

查看:132
本文介绍了如何在PHP应用程序中使用Angular 2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名PHP开发人员,我开始学习Angular2.但是我不知道如何在PHP中使用它. 可以将Angular用作前端吗? 我该怎么办? 如何在未安装Node.js的共享主机上使用它?

I am a PHP developer and I started learning Angular2. But I don't know how to use it with PHP. Is it possible using Angular just as frontend? What I must to do? How to use it on shared hosting without Node.js installed?

推荐答案

我作为长期从事PHP开发人员的2美分,已经在Angular2上工作了很多.

My 2 cents as a long time PHP developer who has been playing with Angular2 quite a bit.

作为PHP开发人员,您希望PHP呈现HTML页面并发送给客户端.您将不会使用Angular2做到这一点.所有在PHP中进行的处理,构建数据表,列表或Angular现在要做的任何事情.

As a PHP developer, you're expecting to have your PHP render an HTML page and send to the client. You won't be doing that with Angular2. All that processing that would take place in PHP, building data tables, lists, or whatever is now Angular's job.

您现在要使用PHP进行的唯一操作就是简单地发送JSON响应.其他人已经在上面说了这一点.

The only thing you're gonna do with PHP now is simply send JSON responses. Others have said this already above.

我假设自从您问这个问题以来,您几乎没有使用Angular2的经验.所以这是交易:

I'm assuming that since you're asking this you have little to no experience working with Angular2. So here's the deal:

了解如何在本地计算机上使用Node和NPM.了解如何使用NPM设置空的Angular2项目.在本地计算机上进行游戏和开发.

Learn how to use Node and NPM on your local machine. Learn how to use NPM to set up your empty Angular2 project. Play and develop on your local machine.

当您准备好加载数据时,PHP可以通过将JSON数据发送到前端供Angular使用来参与其中.

When your ready to load in data, PHP can get involved by sending JSON data down to the front end for Angular to use.

当您准备好将Angular2应用程序投入全球使用时,您可以使用许多构建选项.您需要将代码从Typescript编译为Javascript.

When you're ready to put your Angular2 app online for the world you have a number of build options. You need to compile your code from Typescript to Javascript.

我一直在使用Angular CLI工具.这样我就可以运行"ng build",然后对应用进行编译.

I've been using the Angular CLI tool. That lets me just run "ng build" and the app gets compiled.

然后,我可以将其生成的文件夹上载到我的apache服务器,并且可以正常工作. Angular CLI创建了一个名为"dist"的文件夹,其中包含您的前端所需的所有内容.

Then I can upload the folder it generates up to my apache server and it works. The Angular CLI makes a folder called "dist" that contains all the stuff your front end will need.

那块蛋糕.

这篇关于如何在PHP应用程序中使用Angular 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆