How can I use Angular 2 in PHP application?

前端 未结 4 1958
长情又很酷
长情又很酷 2020-12-13 19:36

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

4条回答
  •  庸人自扰
    2020-12-13 20:34

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

    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.

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

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

    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.

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

    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.

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

    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.

    Piece of cake.

提交回复
热议问题