What application structure to use with AngularJS and Laravel?

前端 未结 3 604
孤街浪徒
孤街浪徒 2020-12-13 02:21

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.

I mixed my views with Angu

3条回答
  •  星月不相逢
    2020-12-13 02:47

    There are two ways to combine these frameworks:

    1. Only client-side rendering

      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.

    2. Server-side and client-side rendering

      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.

提交回复
热议问题