如果Laravel已经用作后端,为什么还要在前端使用AngularJs? [英] Why use AngularJs in frontend if Laravel is already used as backend?

查看:193
本文介绍了如果Laravel已经用作后端,为什么还要在前端使用AngularJs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道AngularJs是FrontEnd,而Laravel是Backend,但是我的问题是:

I know that AngularJs is FrontEnd and Laravel is Backend but my questions is:

为什么我首先需要通过laravel完成我需要的所有工作时使用AngularJs?

Why do I need to use AngularJs in the first place where everything I need is done through Laravel ?

据我了解,我可以使用 JS PHP 两种语言制作应用程序,但是我发现很多用户都将这两种语言同时使用似乎是一种矫kill过正,所以有人可以用最简单的答案形式进行解释.

From what I understood is that I can make an app with either langs JS or PHP, but I find lots of users use both which for me as a beginner it seems like an overkill, so could someone please explain in the simplest possible form of an answer.

在同一项目中使用两者有什么好处? 以及当您同时使用MVC和MVC时,通常如何构造app/folders?

What is the benefit of using both in the same project ? And how do you usually structure your app/folders when you use both specially that both are MVC ?

推荐答案

我怀疑该问题可能与stackoverflow的质量准则相冲突,并且您可能最好问两个独立的问题.即

I suspect the question may conflict with stackoverflow's quality guidelines and you may almost be better asking two separate questions. i.e.

  1. 何时/为什么学习/在wep项目中使用角度
  2. 如何设置文件夹结构

要设置文件夹结构,请查看这些资源

For setting up the folder structure, check out these resources

http://scotch.io/tutorials/php /create-laravel和angular-single-page-comment-application https://www.youtube.com/watch?v=hqAyiqUs93c

我只能说一句为什么我将laravel与angularjs一起使用,而您可以在不使用Angular的情况下使用laravel是正确的,但是我同时使用laravel和laravel的原因是因为在某些方面javascript更适合比服务器端应用程序

I can only really speak to why I use laravel with angularjs and you are right that you can use laravel without angular, but the reason I use angular as well as laravel is because there are some things that javascript is just better positioned for than server side apps e.g.

  • 只要您要检查/处理一些小事情,例如使用用户在表单中输入的电子邮件地址是否有效,都可以使用ajax而不需要重新加载页面.
  • 速度更快,因为当您将ajax返回服务器时,不必加载整个页面,而只需加载所需的部分.
  • 您可以立即向用户提供反馈-例如当他们填写表格时-您可以检查他们的输入是否有效,并立即提供反馈. 使用lavavel,您必须执行往返于服务器的往返操作,并可能返回错误消息的集合.
  • Using ajax and not having to reload the page whenever you want to check/process some small thing, like whether an email address a user types into a form is valid or not.
  • its faster because when you ajax back to the server, you dont have to load the entire page, just the pieces that are needed.
  • You can give immediate feedback to the user - e.g. when they are filling out a form - you can check that their input validates and give them feedback immediately. With lavavel you have to perform a round trip back to the server and possibly return a collection of error messages.

因此,如果您希望您的网站/webapp拥有这些好处,则需要使用javascript编写功能. 我不能说我曾经使用所有框架来说过Angular是最好的框架,但是对于我来说,angular提供了一个集成解决方案套件,并解决了一系列问题.似乎运作良好的架构.

So if you want your website/webapp to have those benefits you need to write the functionality in javascript. I can't say I have used all the frameworks to then say that angular is the best one, but for me angular provides an integrated suite of solutions and to a wide range of issues, on top of an architecture that seems to work well.

我认为这部分是为什么要学习许多新概念并且对这些组件的需求并不明显的原因. 这可能是由于您正在使用某个组件来执行某些功能(例如,使用$ scope对象在控制器和视图之间中继数据,也可以起到较大作用,例如保持视图与控制器之间的分离-这有助于组织代码,可测试性以及其他因素.

I think this is partly why there are quite a few new concepts to learn and the need for these components is not immediately obvious.
This may be due to the fact that a component you are using to perform some function, e.g. using a $scope object to relay data between a controller and a view, also serves a function in the bigger picture, e.g. maintaining separation between the view and the controller - which helps with organising code, testability as well as other factors.

如果您同时使用角度和Laravel(而不是单独使用Laravel),则可以选择为用户提供这些好处,因为您有更多可用的选择,例如在最适合您的应用程序和用户需求的地方使用laravel,或者在可提供最佳结果的位置使用laravel-最终您将拥有一个更好的Web应用程序.

If you use angular as well as Laravel (as opposed to just Laravel by itself) you will then have the option of giving your users these benefits, because you have more options available e.g. use laravel where it best suits the requirements of your app and users or use angular where it gives the best result - and you will have a better web app in the end.

这篇关于如果Laravel已经用作后端,为什么还要在前端使用AngularJs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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