简体   繁体   English

LAMP堆栈中的角度2

[英]Angular 2 in LAMP Stack

I come from a PHP background and I have used traditional JS frameworks like Jquery and Angular 1 to some extent. 我来自PHP背景,我在某种程度上使用了传统的JS框架,如Jquery和Angular 1。 I just started learning Angular 2. I have gone through multiple sites and demos, code generators like angular-cli, vulgar etc. and all of them work as expected. 我刚刚开始学习Angular 2.我经历过多个站点和演示,像angular-cli,粗俗等代码生成器,所有这些都按预期工作。 No problems till now. 到现在为止没问题。

I work on windows. 我在窗户上工作。 So whenever I need to run any angular 2 demo application, I need to run at least 2 or 3 commands on different command prompts and they all need to be continuously running like ng serve, npm start, gulp etc.. 因此,每当我需要运行任何角度2演示应用程序时,我需要在不同的命令提示上运行至少2或3个命令,并且它们都需要连续运行,如ng serve,npm start,gulp等。

Suppose I want to create a simple php application with 3 php files. 假设我想用3个php文件创建一个简单的php应用程序。 Page 1 is where the angular2 app should be running. 第1页是angular2 app应该运行的地方。 Within Page 1, there will be links to page 2 and page 3 php files along with additional routes that with be shown using angular2 routes. 在第1页中,将有第2页和第3页php文件的链接以及使用angular2路由显示的其他路由。

Now since all demos I have seen use typescript, how should I do it in php? 既然我见过的所有演示都使用了打字稿,我该如何在php中完成呢?

I have used angular1 with PHP and it was as simple as importing a script file. 我使用了angular1和PHP,它就像导入脚本文件一样简单。

Can I just import some script files and have the angular2 app running within a php page? 我可以导入一些脚本文件并在php页面中运行angular2应用程序吗? Do I have to run all those(npm,ng,gulp) commands to have the angular2 app running on a php page? 我是否必须运行所有这些(npm,ng,gulp)命令才能在php页面上运行angular2应用程序?

Concerning the TypeScript part: 关于TypeScript部分:

Now since all demos I have seen use typescript, how should I use it in php? 既然我见过的所有演示都使用了打字稿,我应该如何在php中使用它?

...remember that TypeScript is a superset of JavaScript, and transpiles to JavaScript. ...请记住,TypeScript是JavaScript的超集 ,并且转换为JavaScript。 So you might have a process that transpiles your TypeScript app code to JavaScript before you load your page, and runs it in the browser as JavaScript. 因此,在加载页面之前,您可能会有一个将TypeScript应用程序代码转换为JavaScript的过程,并在浏览器中以JavaScript的形式运行它。 Or, you can also run TypeScript in the browser (see this Stack Answer for more info). 或者,您也可以在浏览器中运行TypeScript(有关详细信息,请参阅此堆栈答案 )。

When you run through the Angular 2 tutorials, you will see that as you are writing TypeScript, it creates JavaScript files for you. 当您运行Angular 2教程时,您将看到在编写TypeScript时,它会为您创建JavaScript文件。 The app that runs in the Tutorial (using Node.js) is serving JavaScript, not TypeScript. 在教程中运行的应用程序(使用Node.js)是提供JavaScript,而不是TypeScript。 So, as you mentioned: 所以,正如你所说:

I have used angular1 with PHP and it was as simple as importing a script file. 我使用了angular1和PHP,它就像导入脚本文件一样简单。

Nothing will change there. 没有什么会改变。 The only additional step is getting the TypeScript transpiled to JavaScript. 唯一的另一步是将TypeScript转换为JavaScript。 For that you can checkout SystemJS (that's what the Angular 2 turotials use) or WebPack (which the Angular 2 also has docs on here , which both have plugins/bundlers for doing that for you. 为此你可以检查SystemJS(这是Angular 2 turotials使用的)或WebPack(Angular 2也有这里的文档,它们都有插件/捆绑器为你做这件事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM