简体   繁体   English

Laravel + Angular-页面未加载

[英]Laravel + Angular - Page not loading

Im starting to build a new app with laravel and decided to try out angular.js as well. 我开始使用laravel构建新应用,并决定尝试使用angular.js。 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. 因此,我将使用一种混合方法,在该方法中,登录要在angular之外进行,然后我要在主页上使用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: 这是我的routes.php文件:

// 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: app / views / admin / layouts / master.blade.php文件:

<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 公共/ JS /管理/ 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) public / js / admin / controllers / documentsController.js(目前尚无任何功能)

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

}]);

and finally my template: app/views/admin/documents/index.php 最后是我的模板: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 :) 提前致谢 :)

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 无论如何,您应该在网络控制台(404)中看到错误,导致无法加载模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM