D
D
dk-web2016-04-15 19:17:44
Angular
dk-web, 2016-04-15 19:17:44

Routing in laravel+angularjs?

I'm trying to make a bunch of laravel and angular.
And I see completely different routing methods - ngRoute and ui-routing. I can’t immediately understand what is what ...
the task is banal to make navigation without reloading the page ...

<ul class="nav navbar-nav">
                    <li><a href="/home">Home</a></li>
                    <li><a href="/sources">Sources</a></li>
                </ul>

in app.js
var myApp = angular.module('myApp', ['ngRoute','sourceCtrl', 'sourceService']);

myApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/sources', {
        url: '/sources',
        controller: 'sourceCtrl'
      }).
      when('/home', {
        url: '/home',
        controller: ''
      }).
      otherwise({
        redirectTo: '/'
      });
  }]);

In theory, I should use the "local" routing to call the Laravel controller, which will give the view ...
but it does not work. Tried with tempmplateUrl too. I use blade
I would be grateful for advice on where to dig from the fence ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2016-04-15
@Alex_Wells

Forget about Laravel routing. Make the main page / in the Laravel routing, give the template, and then use the routing of the angular itself. Which one - decide for yourself. For API routes (Angular's call to the site itself, backend), select a subdomain or just make a group with a prefix.
Blade don't touch at all. Output a clean html code, and fill in the data itself with angular. If you really need some variables from pure Laravel, change the tags, there are plenty of instructions. You can also use {{}} under blade, and raw tags under angular - @{{}}. templateUrl - link to the template. Should be in the public folder. Actually, in order to display the template, there must be some element in the html itself, and the "ng-view" attribute is attached to it.
In general - the sea of ​​guides. Type "laravel and angular app" into Google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question