如何在templateURL中使用角度js的laravel局部视图

Ift*_*lam 5 angularjs laravel-5

我想在角度JS指令中显示一个laravel刀片视图文件

var commentsApp = angular.module('CommentApp',[]);

commentsApp.directive('commentForm',function(){
    return {
        restrict: 'EA',
        replace: 'true'
        templateURL: 'views/comments/comment-form.blade.php'
    }
});
Run Code Online (Sandbox Code Playgroud)

我想通过angular指令使用它而不是 @include('comments.comment-form') 我的问题在哪里?怎么解决这个问题.谢谢.

小智 13

首先,您必须在laravel中定义路线

Route::get('comment-form', function() {
    return view('comments.comment-form');
});
Run Code Online (Sandbox Code Playgroud)

然后你可以在AngularJS中使用它

var commentsApp = angular.module('CommentApp', []);

commentsApp.directive('commentForm', function() {
    return {
        restrict: 'EA',
        replace: 'true',
        templateURL: 'comment-form'
    }
});
Run Code Online (Sandbox Code Playgroud)