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

查看:20
本文介绍了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.

目前我只是用 angular 处理表单验证,但实际上我所有的网站页面都需要 ajax、数据拉取等.

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

我在网上搜索,我看到 angular 视图存储在公共文件夹中,但是由于我的所有页面都将使用 angular,因此最好将我的所有视图存储在公共文件夹中,并将 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.

感谢任何帮助提示.

推荐答案

有两种方法可以组合这些框架:

There are two ways to combine these frameworks:

  1. 仅客户端渲染

  1. Only client-side rendering

这是更简单的方法,大多数网络应用程序都使用这种方法.在这种情况下,您将使用 Laravel 作为将返回 JSON 的 API 端点.Angular 可以通过它的 $http$resource 服务查询这些数据,并编译你存储在公共文件夹中的模板.Angular 模板只是带有指令和一些 {{var}} 语句的 HTML.这样 Angular 也完成了所有的路由.

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 在服务器端进行路由和编译一些模板的更难的方式.例如,您将仅将 Angular 用于站点上的某些交互,就像使用 jQuery 一样.这种方法的好处是性能,因为用户将在第一次访问您的网站时获得完整的 HTML.缺点是你可能要写一些逻辑两次,不能使用 Angular 的一些特性.

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天全站免登陆