try_simple_code try_simple_code - 5 months ago 101
AngularJS Question

How can I use laravel partial view by angular js in templateURL

I want to show a laravel blade view file in angular JS directive by

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

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


I want to use it by angular directive instead of
@include('comments.comment-form')

Where is my problem? How to solve this.
Thank you.

Answer

First u must define route in laravel

Route::get('comment-form', function()
{
    return view('comments.comment-form');
});

Then u can use it in angular

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

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