与AngularJS和Laravel使用什么应用程序结构? [英] What application structure to use with AngularJS and Laravel?

查看:156
本文介绍了与AngularJS和Laravel使用什么应用程序结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始建立一个大型的社交网络,而我还以为我的结构是好的,但事实证明我建立这个逻辑涨得厉害。

I recently started to build a large social network, and and I thought my structure was good but it turned out I built this logic up badly.

我混我的看法与AngularJS(坏主意),跳过叶片延伸,但因为我使用了很多块和边栏包括它成为一个痛苦的对接。

I mixed my views with AngularJS (bad idea), skipped blade extension, but since I'm using a lot of block and sidebar includes it became a pain in the butt.

目前,我只是处理表单验证与棱角分明,但实际上我所有的网站页面都需要AJAX,数据拉动等。

Currently I am just handling form validations with angular, but actually all of my site pages will require ajax, data pulling, etc.

我在寻找周围的网,我看到角视图保存在公共文件夹中,但因为我的所有网页会使用的角度是一个好主意来存储我在公众的所有意见,并只使用Laravel作为后端?

I was searching around the net and I saw that angular views are stored in the public folder, but since all my pages will use angular is it a good idea to store all my views in the public, and just use Laravel as a back end?

我知道这是一个愚蠢的问题,但我困惑了一下。

I know this is a silly question but I'm confused a bit.

任何帮助提示AP preciated。

Any help hint appreciated.

推荐答案

有两种方式,这些框架结合起来:

There are two ways to combine these frameworks:


  1. 只有客户端渲染

  1. Only client-side rendering

这是更简单的方式和大多数Web应用程序使用。在这种情况下,你可以使用Laravel作为一个API端点将返回JSON。角可以查询通过 $ HTTP $资源服务这一数据,并编译模板,你在公共存储夹。角模板与指令和一些{{VAR}}语句只是HTML。这样做角所有的路由了。

This is the easier way and used by most web applications. In this case you would use Laravel as an API endpoint which will return JSON. Angular can query this data through its $http or $resource service and compile the templates, which you store in the public folder. Angular templates are just HTML with directives and some {{var}} statements. This way Angular does all the routing too.

服务器端和客户端渲染

这是很难的方式,其中Laravel会做路由和编译在服务器端的一些模板。你会用角只为你使用jQuery例如方式在网站上的一些互动。这种方法的好处是性能,用户将获得完整的HTML他们访问您的网站的第一次。缺点是,你可能必须写一些逻辑两次,不能使用某些角度的功能。

This is the harder way where Laravel would do the routing and compile some templates on the server-side. You would use Angular only for some interactions on the site in a way you would use jQuery for example. The benefit of this approach is performance as users will get the full HTML the first time they visit your site. The disadvantage is that you may have to write some logic twice and can’t use some of Angular’s features.

这篇关于与AngularJS和Laravel使用什么应用程序结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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