2

Im starting to build a new app with laravel and decided to try out angular.js as well. So I will be using a hybrid approach where the login is made outside angular and then i have a main page where I wanna load the templates using angular.

I got stuck in the loading views part with angular. No errors are shown in the console and the template is not loading as well.

This is my routes.php file:

// Login routes here
   ...    
// Routes protected by auth filter  
Route::group(['prefix' => 'admin', 'before' => 'auth'], function(){

   Route::get('/', 'AdminPagesController@main'); // Main Page
   Route::resource('documents', 'DocumentsController'); 

});

app/views/admin/layouts/master.blade.php file:

<html ng-app="intern">
 <head>
  ...
 </head>
   <body>

    <div ng-view=""></div>

    {{ HTML::script('js/vendor/angular.min.js') }}
    {{ HTML::script('js/vendor/angular-route.min.js') }}
    {{ HTML::script('js/admin/app.js') }}
    {{ HTML::script('js/admin/controllers/documentsController.js') }}

  </body>
</html>

public/js/admin/app.js

'use strict';
 var intern = angular.module('intern', ['ngRoute'], function($interpolateProvider) {
    $interpolateProvider.startSymbol('<%');
    $interpolateProvider.endSymbol('%>');
});

intern.config(function($routeProvider) {
  $routeProvider
     // route for the home page
     .when('/admin', {
        templateUrl : 'app/views/admin/documents/index.php',
        controller  : 'documentsController'
      });

     $routeProvider.otherwise({templateUrl:'app/views/admin/documents/index.php'});
  });

public/js/admin/controllers/documentsController.js (which don't have anything much for now)

intern.controller('documentsController', ['$scope', function(scope){

}]);

and finally my template: app/views/admin/documents/index.php

<div>
   <h1>index documents</h1>
</div>

what am I doing wrong? If you guys need more information please tell me. Thanks in advance :)

1 Answer 1

1

You have to place your templaes into the public folder since the app-folder is not accessible via request from the browser. Alternatively you can write a route for the templates (which is not recommended in my opinion)

Anyway you should see an error in your network-console (404) cause the template cant be loaded

Sign up to request clarification or add additional context in comments.

3 Comments

You are right. Thank you. One more thing, what do you think about this approach of having the login separated from angular? Can I restrict users depending on roles from accessing pages that are loaded with angular.js using laravel filters? Once again thank you Fuzzyma.
I used this approach only 2 weeks ago because I just like the auth-Methods laravel provides. I dont think that it rly matters but I like to do the login-stuff with php still. To protect restricted content you have to keep in mind, that all your requests which get data from the server are restricted via laravel routes and filters. Since a raw view rarely has restricted data in it, its ok to store the views in the public folder.
Thank you for your advices. You really helped a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.